fake_arel 0.6 → 0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +5 -0
- data/lib/fake_arel/extensions.rb +6 -2
- data/lib/fake_arel/rails_3_finders.rb +1 -1
- data/lib/fake_arel.rb +1 -1
- data/spec/fake_arel_spec.rb +6 -2
- data/spec/fixtures/reply.rb +3 -0
- data/spec/test.db +0 -0
- metadata +4 -4
data/README.rdoc
CHANGED
data/lib/fake_arel/extensions.rb
CHANGED
|
@@ -34,8 +34,12 @@ module ActiveRecord
|
|
|
34
34
|
ret = proxy_options
|
|
35
35
|
while local_scope.class == ActiveRecord::NamedScope::Scope
|
|
36
36
|
local_conditions = merge_conditions(local_scope.proxy_options[:conditions])
|
|
37
|
-
if local_conditions
|
|
38
|
-
|
|
37
|
+
if local_conditions && ret[:conditions]
|
|
38
|
+
if !ret[:conditions].index(local_conditions)
|
|
39
|
+
ret[:conditions] = merge_conditions(ret[:conditions], local_scope.proxy_options[:conditions])
|
|
40
|
+
end
|
|
41
|
+
elsif local_conditions
|
|
42
|
+
ret[:conditions] = local_conditions
|
|
39
43
|
end
|
|
40
44
|
ret[:includes] = merge_includes(ret[:includes], local_scope.proxy_options[:includes]) if ret[:includes] || local_scope.proxy_options[:includes]
|
|
41
45
|
ret[:joins] = merge_includes(ret[:joins], local_scope.proxy_options[:joins])
|
|
@@ -9,7 +9,7 @@ module Rails3Finders
|
|
|
9
9
|
named_scope :includes, lambda { |*includes| { :include => includes }}
|
|
10
10
|
named_scope :select, lambda {|*select| {:select => select.join(',') }}
|
|
11
11
|
named_scope :order, lambda {|*order| {:order => order.join(',') }}
|
|
12
|
-
named_scope :joins, lambda {|*join| {:joins => join }}
|
|
12
|
+
named_scope :joins, lambda {|*join| {:joins => join } if join[0]}
|
|
13
13
|
named_scope :from, lambda {|*from| {:from => from }}
|
|
14
14
|
named_scope :having, lambda {|*having| {:having => having }}
|
|
15
15
|
named_scope :group, lambda {|*group| {:group => group }}
|
data/lib/fake_arel.rb
CHANGED
data/spec/fake_arel_spec.rb
CHANGED
|
@@ -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(
|
|
51
|
+
Reply.recent_joins_topic.topic_title_is("ActiveRecord").first.should == Reply.find(5)
|
|
52
52
|
Reply.recent_joins_topic.topic_title_is("Nothin").first.should == nil
|
|
53
53
|
end
|
|
54
54
|
|
|
@@ -75,7 +75,11 @@ describe "chained nested named scopes" do
|
|
|
75
75
|
it "should properly chain order scope in definitions by lambda" do
|
|
76
76
|
Reply.topic__id_asc(4).all.should == Reply.find(:all, :conditions => {:topic_id => 4}, :order=>'id asc')
|
|
77
77
|
Reply.order('id desc').topic_id(4).all.should == Reply.find(:all, :conditions => {:topic_id => 4}, :order=>'id desc')
|
|
78
|
-
|
|
78
|
+
topic_4_id_desc = Reply.find(:all, :conditions => {:topic_id => 4}, :order=>'id desc')
|
|
79
|
+
Reply.topic__id_desc(4).all.should == topic_4_id_desc
|
|
80
|
+
Reply.topic__id_desc1(4).all.should == topic_4_id_desc
|
|
81
|
+
Reply.topic__id_desc2(4).all.should == topic_4_id_desc
|
|
82
|
+
Reply.topic__id_desc3(4).all.should == topic_4_id_desc
|
|
79
83
|
end
|
|
80
84
|
|
|
81
85
|
it "should chain order scopes" do
|
data/spec/fixtures/reply.rb
CHANGED
|
@@ -24,6 +24,9 @@ class Reply < ActiveRecord::Base
|
|
|
24
24
|
named_scope :recent_topic_id, lambda{|topic_id| recent.where(:topic_id => topic_id)}
|
|
25
25
|
named_scope :topic__id_asc, lambda{|topic_id| id_asc.where(:topic_id => topic_id)}
|
|
26
26
|
named_scope :topic__id_desc, lambda{|topic_id| id_desc.where(:topic_id => topic_id)}
|
|
27
|
+
named_scope :topic__id_desc1, lambda{|topic_id| where(:topic_id => topic_id).id_desc}
|
|
28
|
+
named_scope :topic__id_desc2, lambda{|topic_id| order('id desc').where(:topic_id => topic_id)}
|
|
29
|
+
named_scope :topic__id_desc3, lambda{|topic_id| where(:topic_id => topic_id).order('id desc')}
|
|
27
30
|
named_scope :topic_id_asc, order('topic_id asc')
|
|
28
31
|
named_scope :topic_id_asc_id_desc, order('topic_id asc').id_desc
|
|
29
32
|
named_scope :lam_topic_id_asc_id_desc, lambda{ topic_id_asc.id_desc }
|
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:
|
|
4
|
+
hash: 5
|
|
5
5
|
prerelease: false
|
|
6
6
|
segments:
|
|
7
7
|
- 0
|
|
8
|
-
-
|
|
9
|
-
version: "0.
|
|
8
|
+
- 7
|
|
9
|
+
version: "0.7"
|
|
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-
|
|
17
|
+
date: 2010-09-13 00:00:00 -04:00
|
|
18
18
|
default_executable:
|
|
19
19
|
dependencies:
|
|
20
20
|
- !ruby/object:Gem::Dependency
|