searchlogic 2.1.5 → 2.1.6

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.rdoc CHANGED
@@ -1,12 +1,19 @@
1
- == 2.1.4
1
+ == 2.1.6 released 2009-07-13
2
2
 
3
- * Check for the existence of id before undefining it.
3
+ * Fix bug when trying to set conditions on conflicting column names with associations. Ex: User.has_many :orders, User.order_count_gt(10) would raise an exception because it was trying to set conditions on the count column for the orders table.
4
+
5
+ == 2.1.5 released 2009-07-12
6
+
7
+ * Check for the existence of id before undefining it, fixes bug in ruby 1.9
8
+
9
+ == 2.1.4 released 2009-07-12
10
+
11
+ * Add ActiveRecordConsistency module to help AR remove duplicate joins easier.
4
12
 
5
13
  == 2.1.3 released 2009-07-12
6
14
 
7
15
  * Added a no conflic resolution for other libraries already using the "search" method. If you have a conflict, use "searchlogic".
8
16
  * Put the hidden order field in a div, to be valid XHTML.
9
- * Add ActiveRecordConsistency module to help AR remove duplicate joins easier.
10
17
 
11
18
  == 2.1.2 released 2009-07-04
12
19
 
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 2
3
3
  :minor: 1
4
- :patch: 5
4
+ :patch: 6
data/lib/searchlogic.rb CHANGED
@@ -3,7 +3,8 @@ require "searchlogic/core_ext/object"
3
3
  require "searchlogic/active_record_consistency"
4
4
  require "searchlogic/named_scopes/conditions"
5
5
  require "searchlogic/named_scopes/ordering"
6
- require "searchlogic/named_scopes/associations"
6
+ require "searchlogic/named_scopes/association_conditions"
7
+ require "searchlogic/named_scopes/association_ordering"
7
8
  require "searchlogic/named_scopes/alias_scope"
8
9
  require "searchlogic/search"
9
10
 
@@ -11,7 +12,8 @@ Proc.send(:include, Searchlogic::CoreExt::Proc)
11
12
  Object.send(:include, Searchlogic::CoreExt::Object)
12
13
  ActiveRecord::Base.extend(Searchlogic::NamedScopes::Conditions)
13
14
  ActiveRecord::Base.extend(Searchlogic::NamedScopes::Ordering)
14
- ActiveRecord::Base.extend(Searchlogic::NamedScopes::Associations)
15
+ ActiveRecord::Base.extend(Searchlogic::NamedScopes::AssociationConditions)
16
+ ActiveRecord::Base.extend(Searchlogic::NamedScopes::AssociationOrdering)
15
17
  ActiveRecord::Base.extend(Searchlogic::NamedScopes::AliasScope)
16
18
  ActiveRecord::Base.extend(Searchlogic::Search::Implementation)
17
19
 
@@ -1,7 +1,7 @@
1
1
  module Searchlogic
2
2
  module NamedScopes
3
3
  # Handles dynamically creating named scopes for associations.
4
- module Associations
4
+ module AssociationConditions
5
5
  def condition?(name) # :nodoc:
6
6
  super || association_condition?(name) || association_alias_condition?(name)
7
7
  end
@@ -43,9 +43,6 @@ module Searchlogic
43
43
  elsif details = association_alias_condition_details(name)
44
44
  create_association_alias_condition(details[:association], details[:column], details[:condition], args)
45
45
  send(name, *args)
46
- elsif details = association_ordering_condition_details(name)
47
- create_association_ordering_condition(details[:association], details[:order_as], details[:column], args)
48
- send(name, *args)
49
46
  else
50
47
  super
51
48
  end
@@ -53,7 +50,7 @@ module Searchlogic
53
50
 
54
51
  def association_condition_details(name)
55
52
  associations = reflect_on_all_associations.collect { |assoc| assoc.name }
56
- if name.to_s =~ /^(#{associations.join("|")})_(\w+)_(#{Conditions::PRIMARY_CONDITIONS.join("|")})$/
53
+ if !local_condition?(name) && name.to_s =~ /^(#{associations.join("|")})_(\w+)_(#{Conditions::PRIMARY_CONDITIONS.join("|")})$/
57
54
  {:association => $1, :column => $2, :condition => $3}
58
55
  end
59
56
  end
@@ -64,7 +61,7 @@ module Searchlogic
64
61
 
65
62
  def association_alias_condition_details(name)
66
63
  associations = reflect_on_all_associations.collect { |assoc| assoc.name }
67
- if name.to_s =~ /^(#{associations.join("|")})_(\w+)_(#{Conditions::ALIAS_CONDITIONS.join("|")})$/
64
+ if !local_condition?(name) && name.to_s =~ /^(#{associations.join("|")})_(\w+)_(#{Conditions::ALIAS_CONDITIONS.join("|")})$/
68
65
  {:association => $1, :column => $2, :condition => $3}
69
66
  end
70
67
  end
@@ -77,17 +74,6 @@ module Searchlogic
77
74
  (class << self; self; end).class_eval { alias_method alias_name, primary_name }
78
75
  end
79
76
 
80
- def association_ordering_condition_details(name)
81
- associations = reflect_on_all_associations.collect { |assoc| assoc.name }
82
- if name.to_s =~ /^(ascend|descend)_by_(#{associations.join("|")})_(\w+)$/
83
- {:order_as => $1, :association => $2, :column => $3}
84
- end
85
- end
86
-
87
- def create_association_ordering_condition(association_name, order_as, column, args)
88
- named_scope("#{order_as}_by_#{association_name}_#{column}", association_condition_options(association_name, "#{order_as}_by_#{column}", args))
89
- end
90
-
91
77
  def association_condition_options(association_name, association_condition, args)
92
78
  association = reflect_on_association(association_name.to_sym)
93
79
  scope = association.klass.send(association_condition, *args)
@@ -0,0 +1,27 @@
1
+ module Searchlogic
2
+ module NamedScopes
3
+ # Handles dynamically creating named scopes for associations.
4
+ module AssociationOrdering
5
+ private
6
+ def method_missing(name, *args, &block)
7
+ if details = association_ordering_condition_details(name)
8
+ create_association_ordering_condition(details[:association], details[:order_as], details[:column], args)
9
+ send(name, *args)
10
+ else
11
+ super
12
+ end
13
+ end
14
+
15
+ def association_ordering_condition_details(name)
16
+ associations = reflect_on_all_associations.collect { |assoc| assoc.name }
17
+ if !local_condition?(name) && name.to_s =~ /^(ascend|descend)_by_(#{associations.join("|")})_(\w+)$/
18
+ {:order_as => $1, :association => $2, :column => $3}
19
+ end
20
+ end
21
+
22
+ def create_association_ordering_condition(association_name, order_as, column, args)
23
+ named_scope("#{order_as}_by_#{association_name}_#{column}", association_condition_options(association_name, "#{order_as}_by_#{column}", args))
24
+ end
25
+ end
26
+ end
27
+ end
@@ -95,6 +95,11 @@ module Searchlogic
95
95
 
96
96
  # Is the name of the method a valid condition that can be dynamically created?
97
97
  def condition?(name)
98
+ local_condition?(name)
99
+ end
100
+
101
+ # Is the condition for a local column, not an association
102
+ def local_condition?(name)
98
103
  primary_condition?(name) || alias_condition?(name)
99
104
  end
100
105
 
@@ -2,7 +2,7 @@ module Searchlogic
2
2
  module NamedScopes
3
3
  # Handles dynamically creating named scopes for orderin by columns.
4
4
  module Ordering
5
- def condition?(name) # :nodoc:
5
+ def local_condition?(name) # :nodoc:
6
6
  super || order_condition?(name)
7
7
  end
8
8
 
@@ -37,7 +37,7 @@ module Searchlogic
37
37
  end
38
38
 
39
39
  def order_condition_details(name)
40
- if name.to_s =~ /^(ascend|descend)_by_(\w+)$/
40
+ if name.to_s =~ /^(ascend|descend)_by_(#{column_names.join("|")})$/
41
41
  {:order_as => $1, :column => $2}
42
42
  elsif name.to_s =~ /^order$/
43
43
  {}
data/searchlogic.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{searchlogic}
5
- s.version = "2.1.5"
5
+ s.version = "2.1.6"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Ben Johnson of Binary Logic"]
9
- s.date = %q{2009-07-12}
9
+ s.date = %q{2009-07-13}
10
10
  s.email = %q{bjohnson@binarylogic.com}
11
11
  s.extra_rdoc_files = [
12
12
  "LICENSE",
@@ -25,7 +25,8 @@ Gem::Specification.new do |s|
25
25
  "lib/searchlogic/core_ext/object.rb",
26
26
  "lib/searchlogic/core_ext/proc.rb",
27
27
  "lib/searchlogic/named_scopes/alias_scope.rb",
28
- "lib/searchlogic/named_scopes/associations.rb",
28
+ "lib/searchlogic/named_scopes/association_conditions.rb",
29
+ "lib/searchlogic/named_scopes/association_ordering.rb",
29
30
  "lib/searchlogic/named_scopes/conditions.rb",
30
31
  "lib/searchlogic/named_scopes/ordering.rb",
31
32
  "lib/searchlogic/rails_helpers.rb",
@@ -35,7 +36,8 @@ Gem::Specification.new do |s|
35
36
  "spec/core_ext/object_spec.rb",
36
37
  "spec/core_ext/proc_spec.rb",
37
38
  "spec/named_scopes/alias_scope_spec.rb",
38
- "spec/named_scopes/associations_spec.rb",
39
+ "spec/named_scopes/association_conditions_spec.rb",
40
+ "spec/named_scopes/association_ordering_spec.rb",
39
41
  "spec/named_scopes/conditions_spec.rb",
40
42
  "spec/named_scopes/ordering_spec.rb",
41
43
  "spec/search_spec.rb",
@@ -51,7 +53,8 @@ Gem::Specification.new do |s|
51
53
  "spec/core_ext/object_spec.rb",
52
54
  "spec/core_ext/proc_spec.rb",
53
55
  "spec/named_scopes/alias_scope_spec.rb",
54
- "spec/named_scopes/associations_spec.rb",
56
+ "spec/named_scopes/association_conditions_spec.rb",
57
+ "spec/named_scopes/association_ordering_spec.rb",
55
58
  "spec/named_scopes/conditions_spec.rb",
56
59
  "spec/named_scopes/ordering_spec.rb",
57
60
  "spec/search_spec.rb",
@@ -1,6 +1,6 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
2
 
3
- describe "Associations" do
3
+ describe "Association Conditions" do
4
4
  it "should create a named scope" do
5
5
  Company.users_username_like("bjohnson").proxy_options.should == User.username_like("bjohnson").proxy_options.merge(:joins => :users)
6
6
  end
@@ -50,22 +50,6 @@ describe "Associations" do
50
50
  Company.users_orders_total_gt(10).proxy_options.should == Order.total_gt(10).proxy_options.merge(:joins => {:users => :orders})
51
51
  end
52
52
 
53
- it "should allow ascending" do
54
- Company.ascend_by_users_username.proxy_options.should == User.ascend_by_username.proxy_options.merge(:joins => :users)
55
- end
56
-
57
- it "should allow descending" do
58
- Company.descend_by_users_username.proxy_options.should == User.descend_by_username.proxy_options.merge(:joins => :users)
59
- end
60
-
61
- it "should allow deep ascending" do
62
- Company.ascend_by_users_orders_total.proxy_options.should == Order.ascend_by_total.proxy_options.merge(:joins => {:users => :orders})
63
- end
64
-
65
- it "should allow deep descending" do
66
- Company.descend_by_users_orders_total.proxy_options.should == Order.descend_by_total.proxy_options.merge(:joins => {:users => :orders})
67
- end
68
-
69
53
  it "should include optional associations" do
70
54
  pending # this is a problem with using inner joins and left outer joins
71
55
  Company.create
@@ -0,0 +1,19 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
+
3
+ describe "Association Ordering" do
4
+ it "should allow ascending" do
5
+ Company.ascend_by_users_username.proxy_options.should == User.ascend_by_username.proxy_options.merge(:joins => :users)
6
+ end
7
+
8
+ it "should allow descending" do
9
+ Company.descend_by_users_username.proxy_options.should == User.descend_by_username.proxy_options.merge(:joins => :users)
10
+ end
11
+
12
+ it "should allow deep ascending" do
13
+ Company.ascend_by_users_orders_total.proxy_options.should == Order.ascend_by_total.proxy_options.merge(:joins => {:users => :orders})
14
+ end
15
+
16
+ it "should allow deep descending" do
17
+ Company.descend_by_users_orders_total.proxy_options.should == Order.descend_by_total.proxy_options.merge(:joins => {:users => :orders})
18
+ end
19
+ end
@@ -250,4 +250,8 @@ describe "Conditions" do
250
250
  Order.named_scope_options(:total_gt).searchlogic_arg_type.should == :float
251
251
  end
252
252
  end
253
+
254
+ it "should have priorty to columns over conflicting association conditions" do
255
+ Company.users_count_gt(10)
256
+ end
253
257
  end
@@ -20,4 +20,8 @@ describe "Ordering" do
20
20
  it "should have order" do
21
21
  User.order("ascend_by_username").proxy_options.should == User.ascend_by_username.proxy_options
22
22
  end
23
+
24
+ it "should have priorty to columns over conflicting association columns" do
25
+ Company.ascend_by_users_count
26
+ end
23
27
  end
data/spec/spec_helper.rb CHANGED
@@ -11,6 +11,7 @@ ActiveRecord::Schema.define(:version => 1) do
11
11
  create_table :companies do |t|
12
12
  t.datetime :created_at
13
13
  t.datetime :updated_at
14
+ t.integer :users_count, :default => 0
14
15
  end
15
16
 
16
17
  create_table :users do |t|
@@ -50,7 +51,7 @@ Spec::Runner.configure do |config|
50
51
  end
51
52
 
52
53
  class User < ActiveRecord::Base
53
- belongs_to :company
54
+ belongs_to :company, :counter_cache => true
54
55
  has_many :orders, :dependent => :destroy
55
56
  alias_scope :username_has, lambda { |value| username_like(value) }
56
57
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: searchlogic
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.5
4
+ version: 2.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Johnson of Binary Logic
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-07-12 00:00:00 -04:00
12
+ date: 2009-07-13 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -44,7 +44,8 @@ files:
44
44
  - lib/searchlogic/core_ext/object.rb
45
45
  - lib/searchlogic/core_ext/proc.rb
46
46
  - lib/searchlogic/named_scopes/alias_scope.rb
47
- - lib/searchlogic/named_scopes/associations.rb
47
+ - lib/searchlogic/named_scopes/association_conditions.rb
48
+ - lib/searchlogic/named_scopes/association_ordering.rb
48
49
  - lib/searchlogic/named_scopes/conditions.rb
49
50
  - lib/searchlogic/named_scopes/ordering.rb
50
51
  - lib/searchlogic/rails_helpers.rb
@@ -54,7 +55,8 @@ files:
54
55
  - spec/core_ext/object_spec.rb
55
56
  - spec/core_ext/proc_spec.rb
56
57
  - spec/named_scopes/alias_scope_spec.rb
57
- - spec/named_scopes/associations_spec.rb
58
+ - spec/named_scopes/association_conditions_spec.rb
59
+ - spec/named_scopes/association_ordering_spec.rb
58
60
  - spec/named_scopes/conditions_spec.rb
59
61
  - spec/named_scopes/ordering_spec.rb
60
62
  - spec/search_spec.rb
@@ -91,7 +93,8 @@ test_files:
91
93
  - spec/core_ext/object_spec.rb
92
94
  - spec/core_ext/proc_spec.rb
93
95
  - spec/named_scopes/alias_scope_spec.rb
94
- - spec/named_scopes/associations_spec.rb
96
+ - spec/named_scopes/association_conditions_spec.rb
97
+ - spec/named_scopes/association_ordering_spec.rb
95
98
  - spec/named_scopes/conditions_spec.rb
96
99
  - spec/named_scopes/ordering_spec.rb
97
100
  - spec/search_spec.rb