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 CHANGED
@@ -48,7 +48,7 @@ http://github.com/gammons/fake_arel
48
48
 
49
49
  (The MIT License)
50
50
 
51
- Copyright (c) 2010 FIXME full name
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
@@ -9,7 +9,18 @@ module ActiveRecord
9
9
  when Hash
10
10
  options
11
11
  when Scope
12
- options.proxy_options
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)
@@ -1,12 +1,3 @@
1
- module ActiveRecord
2
- class Base
3
-
4
- def self.grant_scope_2
5
- p "BANGO"
6
- end
7
- end
8
- end
9
-
10
1
  module WithScopeReplacement
11
2
  def self.included(base)
12
3
  base.class_eval do
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.1'
11
+ VERSION = '0.1.1'
12
12
  ActiveRecord::Base.send :include, Rails3Finders
13
13
  ActiveRecord::Base.send :include, WithScopeReplacement
14
14
  end
@@ -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
@@ -27,3 +27,9 @@ brave:
27
27
  topic_id: 4
28
28
  content: "AR doesn't scare me a bit"
29
29
  created_at: <%= 10.minutes.ago.to_s(:db) %>
30
+
31
+ thang:
32
+ id: 6
33
+ topic_id: 4
34
+ content: "AR This is some more content"
35
+ created_at: <%= 10.hours.ago.to_s(:db) %>
@@ -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: 9
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- version: "0.1"
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-23 00:00:00 -04:00
18
+ date: 2010-07-29 00:00:00 -04:00
18
19
  default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency