fake_arel 0.1 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +1 -1
- data/lib/fake_arel/extensions.rb +12 -1
- data/lib/fake_arel/with_scope_replacement.rb +0 -9
- data/lib/fake_arel.rb +1 -1
- data/spec/fake_arel_spec.rb +10 -1
- data/spec/fixtures/replies.yml +6 -0
- data/spec/fixtures/reply.rb +4 -0
- data/spec/test.db +0 -0
- metadata +4 -3
data/README.rdoc
CHANGED
@@ -48,7 +48,7 @@ http://github.com/gammons/fake_arel
|
|
48
48
|
|
49
49
|
(The MIT License)
|
50
50
|
|
51
|
-
Copyright (c) 2010
|
51
|
+
Copyright (c) 2010 Grant Ammons (grant@pipelinedealsco.com)
|
52
52
|
|
53
53
|
Permission is hereby granted, free of charge, to any person obtaining
|
54
54
|
a copy of this software and associated documentation files (the
|
data/lib/fake_arel/extensions.rb
CHANGED
@@ -9,7 +9,18 @@ module ActiveRecord
|
|
9
9
|
when Hash
|
10
10
|
options
|
11
11
|
when Scope
|
12
|
-
|
12
|
+
# unspin the scope and generate a hash
|
13
|
+
local_scope = options.proxy_scope
|
14
|
+
ret = options.proxy_options
|
15
|
+
while local_scope.class == ActiveRecord::NamedScope::Scope
|
16
|
+
unless ret[:conditions].to_s.index merge_conditions(local_scope.proxy_options[:conditions])
|
17
|
+
ret[:conditions] = merge_conditions(ret[:conditions], local_scope.proxy_options[:conditions])
|
18
|
+
ret[:includes] = merge_includes(ret[:includes], local_scope.proxy_options[:includes]) if ret[:includes] or local_scope.proxy_options[:includes]
|
19
|
+
ret[:joins] = merge_includes(ret[:joins], local_scope.proxy_options[:joins])
|
20
|
+
end
|
21
|
+
local_scope = local_scope.proxy_scope
|
22
|
+
end
|
23
|
+
ret
|
13
24
|
when Proc
|
14
25
|
if self.model_name != parent_scope.model_name
|
15
26
|
options.bind(parent_scope).call(*args)
|
data/lib/fake_arel.rb
CHANGED
data/spec/fake_arel_spec.rb
CHANGED
@@ -34,7 +34,7 @@ describe "Basics" do
|
|
34
34
|
end
|
35
35
|
|
36
36
|
it "should work with scope and with exclusive scope" do
|
37
|
-
Reply.find_all_but_first.map(&:id).should == [2,3,4,5]
|
37
|
+
Reply.find_all_but_first.map(&:id).should == [2,3,4,5,6]
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
@@ -43,3 +43,12 @@ describe "to sql" do
|
|
43
43
|
Topic.joins(:replies).limit(1).to_sql
|
44
44
|
end
|
45
45
|
end
|
46
|
+
|
47
|
+
describe "chained nested named scopes" do
|
48
|
+
it "should be able to chain named scopes within a named_scope" do
|
49
|
+
Reply.recent_with_content_like_ar.should == Reply.find(:all, :conditions => "id = 5")
|
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)
|
52
|
+
Reply.recent_joins_topic.topic_title_is("Nothin").first.should == nil
|
53
|
+
end
|
54
|
+
end
|
data/spec/fixtures/replies.yml
CHANGED
data/spec/fixtures/reply.rb
CHANGED
@@ -3,6 +3,10 @@ class Reply < ActiveRecord::Base
|
|
3
3
|
|
4
4
|
named_scope :recent, where('replies.created_at > ?', 15.minutes.ago)
|
5
5
|
named_scope :recent_limit_1, where('replies.created_at > ?', 15.minutes.ago).limit(1)
|
6
|
+
named_scope :recent_with_content_like_ar, recent.where('lower(content) like ?', "AR%")
|
7
|
+
named_scope :recent_with_content_like_ar_and_id_4, recent.where('lower(content) like ?', "AR%").where("id = 4")
|
8
|
+
named_scope :recent_joins_topic, recent.joins(:topic)
|
9
|
+
named_scope :topic_title_is, lambda {|topic_title| where("topics.title like ?", topic_title + "%") }
|
6
10
|
|
7
11
|
named_scope :arel_id, :conditions => "id = 1"
|
8
12
|
named_scope :arel_id_with_lambda, lambda {|aid| arel_id}
|
data/spec/test.db
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fake_arel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Grant Ammons
|
@@ -14,7 +15,7 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2010-07-
|
18
|
+
date: 2010-07-29 00:00:00 -04:00
|
18
19
|
default_executable:
|
19
20
|
dependencies:
|
20
21
|
- !ruby/object:Gem::Dependency
|