fake_arel 0.1.1 → 0.1.2
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/lib/fake_arel.rb +1 -1
- data/lib/fake_arel/extensions.rb +3 -5
- data/spec/fake_arel_spec.rb +5 -1
- data/spec/fixtures/reply.rb +3 -0
- data/spec/fixtures/schema.rb +7 -1
- data/spec/fixtures/topic.rb +1 -1
- data/spec/fixtures/topics.yml +4 -2
- data/spec/test.db +0 -0
- metadata +3 -3
data/lib/fake_arel.rb
CHANGED
data/lib/fake_arel/extensions.rb
CHANGED
|
@@ -13,11 +13,9 @@ module ActiveRecord
|
|
|
13
13
|
local_scope = options.proxy_scope
|
|
14
14
|
ret = options.proxy_options
|
|
15
15
|
while local_scope.class == ActiveRecord::NamedScope::Scope
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
ret[:joins] = merge_includes(ret[:joins], local_scope.proxy_options[:joins])
|
|
20
|
-
end
|
|
16
|
+
ret[:conditions] = merge_conditions(ret[:conditions], local_scope.proxy_options[:conditions])
|
|
17
|
+
ret[:includes] = merge_includes(ret[:includes], local_scope.proxy_options[:includes]) if ret[:includes] or local_scope.proxy_options[:includes]
|
|
18
|
+
ret[:joins] = merge_includes(ret[:joins], local_scope.proxy_options[:joins])
|
|
21
19
|
local_scope = local_scope.proxy_scope
|
|
22
20
|
end
|
|
23
21
|
ret
|
data/spec/fake_arel_spec.rb
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
require File.dirname(__FILE__) + '/spec_helper.rb'
|
|
2
2
|
require 'reply'
|
|
3
3
|
require 'topic'
|
|
4
|
-
|
|
4
|
+
require 'author'
|
|
5
5
|
|
|
6
6
|
describe "Basics" do
|
|
7
7
|
it "should accomplish basic where" do
|
|
@@ -51,4 +51,8 @@ describe "chained nested named scopes" do
|
|
|
51
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
|
+
|
|
55
|
+
it "should be able to join multiple items" do
|
|
56
|
+
Reply.filter_join_topic_and_author.first.topic.author
|
|
57
|
+
end
|
|
54
58
|
end
|
data/spec/fixtures/reply.rb
CHANGED
|
@@ -8,6 +8,9 @@ class Reply < ActiveRecord::Base
|
|
|
8
8
|
named_scope :recent_joins_topic, recent.joins(:topic)
|
|
9
9
|
named_scope :topic_title_is, lambda {|topic_title| where("topics.title like ?", topic_title + "%") }
|
|
10
10
|
|
|
11
|
+
named_scope :join_topic_and_author, joins(:topic => [:author])
|
|
12
|
+
named_scope :filter_join_topic_and_author, joins(:topic => [:author]).where('lower(replies.content) like ?','AR%')
|
|
13
|
+
|
|
11
14
|
named_scope :arel_id, :conditions => "id = 1"
|
|
12
15
|
named_scope :arel_id_with_lambda, lambda {|aid| arel_id}
|
|
13
16
|
named_scope :arel_id_with_nested_lambda, lambda {|aid| arel_id_with_lambda(aid)}
|
data/spec/fixtures/schema.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
ActiveRecord::Schema.define do
|
|
2
2
|
create_table "topics", :force => true do |t|
|
|
3
|
-
t.column "
|
|
3
|
+
t.column "author_id", :integer
|
|
4
4
|
t.column "title", :string
|
|
5
5
|
t.column "subtitle", :string
|
|
6
6
|
t.column "content", :text
|
|
@@ -14,4 +14,10 @@ ActiveRecord::Schema.define do
|
|
|
14
14
|
t.column "updated_at", :datetime
|
|
15
15
|
t.column "topic_id", :integer
|
|
16
16
|
end
|
|
17
|
+
|
|
18
|
+
create_table "authors", :force => true do |t|
|
|
19
|
+
t.column "name", :string
|
|
20
|
+
t.column "created_at", :datetime
|
|
21
|
+
t.column "updated_at", :datetime
|
|
22
|
+
end
|
|
17
23
|
end
|
data/spec/fixtures/topic.rb
CHANGED
data/spec/fixtures/topics.yml
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
futurama:
|
|
2
2
|
id: 1
|
|
3
|
+
author_id: 1
|
|
3
4
|
title: Isnt futurama awesome?
|
|
4
5
|
subtitle: It really is, isnt it.
|
|
5
6
|
content: I like futurama
|
|
@@ -8,6 +9,7 @@ futurama:
|
|
|
8
9
|
|
|
9
10
|
harvey_birdman:
|
|
10
11
|
id: 2
|
|
12
|
+
author_id: 1
|
|
11
13
|
title: Harvey Birdman is the king of all men
|
|
12
14
|
subtitle: yup
|
|
13
15
|
content: He really is
|
|
@@ -16,7 +18,7 @@ harvey_birdman:
|
|
|
16
18
|
|
|
17
19
|
rails:
|
|
18
20
|
id: 3
|
|
19
|
-
|
|
21
|
+
author_id: 1
|
|
20
22
|
title: Rails is nice
|
|
21
23
|
subtitle: It makes me happy
|
|
22
24
|
content: except when I have to hack internals to fix pagination. even then really.
|
|
@@ -24,7 +26,7 @@ rails:
|
|
|
24
26
|
|
|
25
27
|
ar:
|
|
26
28
|
id: 4
|
|
27
|
-
|
|
29
|
+
author_id: 1
|
|
28
30
|
title: ActiveRecord sometimes freaks me out
|
|
29
31
|
content: "I mean, what's the deal with eager loading?"
|
|
30
32
|
created_at: <%= 15.minutes.ago.to_s(:db) %>
|
data/spec/test.db
CHANGED
|
Binary file
|
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: fake_arel
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
hash:
|
|
4
|
+
hash: 31
|
|
5
5
|
prerelease: false
|
|
6
6
|
segments:
|
|
7
7
|
- 0
|
|
8
8
|
- 1
|
|
9
|
-
-
|
|
10
|
-
version: 0.1.
|
|
9
|
+
- 2
|
|
10
|
+
version: 0.1.2
|
|
11
11
|
platform: ruby
|
|
12
12
|
authors:
|
|
13
13
|
- Grant Ammons
|