fake_arel 0.5 → 0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -33,7 +33,10 @@ module ActiveRecord
33
33
  local_scope = proxy_scope
34
34
  ret = proxy_options
35
35
  while local_scope.class == ActiveRecord::NamedScope::Scope
36
- ret[:conditions] = merge_conditions(ret[:conditions], local_scope.proxy_options[:conditions])
36
+ local_conditions = merge_conditions(local_scope.proxy_options[:conditions])
37
+ if local_conditions and ret[:conditions] and not ret[:conditions].index local_conditions
38
+ ret[:conditions] = merge_conditions(ret[:conditions], local_scope.proxy_options[:conditions])
39
+ end
37
40
  ret[:includes] = merge_includes(ret[:includes], local_scope.proxy_options[:includes]) if ret[:includes] || local_scope.proxy_options[:includes]
38
41
  ret[:joins] = merge_includes(ret[:joins], local_scope.proxy_options[:joins])
39
42
  ret[:order] = [local_scope.proxy_options[:order], ret[:order]].select{|o| !o.blank?}.join(',') if ret[:order] || local_scope.proxy_options[:order]
data/lib/fake_arel.rb CHANGED
@@ -8,7 +8,7 @@ require 'fake_arel/with_scope_replacement'
8
8
  require 'fake_arel/rails_3_finders'
9
9
 
10
10
  module FakeArel
11
- VERSION = '0.5'
11
+ VERSION = '0.6'
12
12
  ActiveRecord::Base.send :include, Rails3Finders
13
13
  ActiveRecord::Base.send :include, WithScopeReplacement
14
14
  end
@@ -48,7 +48,7 @@ describe "chained nested named scopes" do
48
48
  it "should be able to chain named scopes within a named_scope" do
49
49
  Reply.recent_with_content_like_ar.should == Reply.find(:all, :conditions => "id = 5")
50
50
  Reply.recent_with_content_like_ar_and_id_4.should == []
51
- Reply.recent_joins_topic.topic_title_is("ActiveRecord").first.should == Reply.find(5)
51
+ Reply.recent_joins_topic.topic_title_is("ActiveRecord").first.should == Reply.find(4)
52
52
  Reply.recent_joins_topic.topic_title_is("Nothin").first.should == nil
53
53
  end
54
54
 
@@ -99,3 +99,28 @@ describe "keep scoped functionality" do
99
99
  Reply.scoped({}).class.should == ActiveRecord::NamedScope::Scope
100
100
  end
101
101
  end
102
+
103
+ describe "not generate redundant queries" do
104
+ # Github issue #8, fake_arel was adding conditions over and over
105
+ # to a names scope.
106
+ it "should not add a billion parens and conditions" do
107
+ pass_1 = Reply.recent.to_sql
108
+ pass_2 = Reply.recent.to_sql
109
+ pass_3 = Reply.recent.to_sql
110
+ pass_1.should == pass_2
111
+ pass_2.should == pass_3
112
+
113
+ pass1 = Reply.filter_join_topic_and_author.to_sql
114
+ pass2 = Reply.filter_join_topic_and_author.to_sql
115
+ pass3 = Reply.filter_join_topic_and_author.to_sql
116
+ pass_1.should == pass_2
117
+ pass_2.should == pass_3
118
+
119
+ pass1 = Reply.recent_joins_topic.topic_title_is('Nothin').to_sql
120
+ pass2 = Reply.recent_joins_topic.topic_title_is('Nothin').to_sql
121
+ pass3 = Reply.recent_joins_topic.topic_title_is('Nothin').to_sql
122
+ pass_1.should == pass_2
123
+ pass_2.should == pass_3
124
+ end
125
+ end
126
+
@@ -2,6 +2,7 @@ class Reply < ActiveRecord::Base
2
2
  belongs_to :topic, :include => [:replies]
3
3
 
4
4
  named_scope :recent, where('replies.created_at > ?', 15.minutes.ago)
5
+ named_scope :recent_two_wheres, where('replies.created_at > ?', 15.minutes.ago).where(:id => 5)
5
6
  named_scope :recent_limit_1, where('replies.created_at > ?', 15.minutes.ago).limit(1)
6
7
  named_scope :recent_with_content_like_ar, recent.where('lower(replies.content) like ?', "AR%")
7
8
  named_scope :recent_with_content_like_ar_and_id_4, recent.where('lower(replies.content) like ?', "AR%").where("id = 4")
data/spec/test.db CHANGED
Binary file
metadata CHANGED
@@ -1,12 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fake_arel
3
3
  version: !ruby/object:Gem::Version
4
- hash: 1
4
+ hash: 7
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 5
9
- version: "0.5"
8
+ - 6
9
+ version: "0.6"
10
10
  platform: ruby
11
11
  authors:
12
12
  - Grant Ammons
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-08-17 00:00:00 -04:00
17
+ date: 2010-08-23 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency