fake_arel 0.9.1 → 0.9.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/fake_arel.gemspec +4 -4
- data/lib/fake_arel/rails_3_finders.rb +8 -1
- data/lib/fake_arel.rb +2 -1
- data/spec/fake_arel_spec.rb +15 -0
- data/spec/test.db +0 -0
- metadata +10 -10
data/fake_arel.gemspec
CHANGED
|
@@ -6,16 +6,16 @@ require 'bundler/version'
|
|
|
6
6
|
|
|
7
7
|
Gem::Specification.new do |s|
|
|
8
8
|
s.name = "fake_arel"
|
|
9
|
-
s.version = "0.9.
|
|
9
|
+
s.version = "0.9.2"
|
|
10
10
|
s.platform = Gem::Platform::RUBY
|
|
11
11
|
s.author = "Grant Ammons"
|
|
12
12
|
s.email = ["grant@pipelinedealsco.com"]
|
|
13
13
|
s.homepage = "http://github.com/gammons/fake_arel"
|
|
14
14
|
s.summary = "A library that simulates Rails 3 ActiveRecord Arel calls using extensions to named_scope."
|
|
15
15
|
|
|
16
|
-
s.add_dependency(
|
|
17
|
-
s.rubyforge_project 'fake_arel'
|
|
16
|
+
s.add_dependency('activerecord', '~>2.3.5')
|
|
17
|
+
s.rubyforge_project = 'fake_arel'
|
|
18
18
|
|
|
19
|
-
s.files = Dir.glob("{bin,lib}/**/*")
|
|
19
|
+
s.files = Dir.glob("{bin,lib}/**/*")
|
|
20
20
|
s.require_path = 'lib'
|
|
21
21
|
end
|
|
@@ -7,7 +7,6 @@ module Rails3Finders
|
|
|
7
7
|
named_scope :offset, lambda {|offset| {:offset => offset}}
|
|
8
8
|
named_scope :limit, lambda {|limit| {:limit => limit}}
|
|
9
9
|
named_scope :includes, lambda { |*includes| { :include => includes }}
|
|
10
|
-
named_scope :select, lambda {|*select| {:select => select.join(',') }}
|
|
11
10
|
named_scope :order, lambda {|*order| {:order => order.join(',') }}
|
|
12
11
|
named_scope :joins, lambda {|*join| {:joins => join } if join[0]}
|
|
13
12
|
named_scope :from, lambda {|*from| {:from => from }}
|
|
@@ -16,6 +15,14 @@ module Rails3Finders
|
|
|
16
15
|
named_scope :readonly, lambda {|readonly| {:readonly => readonly }}
|
|
17
16
|
named_scope :lock, lambda {|lock| {:lock => lock }}
|
|
18
17
|
|
|
18
|
+
def self.select(value = Proc.new)
|
|
19
|
+
if block_given?
|
|
20
|
+
all.select {|*block_args| value.call(*block_args) }
|
|
21
|
+
else
|
|
22
|
+
self.scoped(:select => Array.wrap(value).join(','))
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
19
26
|
__where_fn = lambda do |*where|
|
|
20
27
|
if where.is_a?(Array) and where.size == 1
|
|
21
28
|
{:conditions => where.first}
|
data/lib/fake_arel.rb
CHANGED
|
@@ -6,9 +6,10 @@ require 'fake_arel/singleton_class'
|
|
|
6
6
|
require 'fake_arel/extensions'
|
|
7
7
|
require 'fake_arel/with_scope_replacement'
|
|
8
8
|
require 'fake_arel/rails_3_finders'
|
|
9
|
+
require 'fake_arel/calculations'
|
|
9
10
|
|
|
10
11
|
module FakeArel
|
|
11
|
-
VERSION = '0.9.
|
|
12
|
+
VERSION = '0.9.2'
|
|
12
13
|
ActiveRecord::Base.send :include, Rails3Finders
|
|
13
14
|
ActiveRecord::Base.send :include, WithScopeReplacement
|
|
14
15
|
end
|
data/spec/fake_arel_spec.rb
CHANGED
|
@@ -174,5 +174,20 @@ describe "Fake Arel" do
|
|
|
174
174
|
# an example using joins, as well as a query that returns nothing
|
|
175
175
|
Reply.or(Reply.recent_joins_topic, Reply.topic_title_is("Nothin")).all.map(&:id).should == [5]
|
|
176
176
|
end
|
|
177
|
+
|
|
178
|
+
it "should use select like rails 3 uses select" do
|
|
179
|
+
lambda { Reply.all.select {|r| r.id == 1 }}.should_not raise_error
|
|
180
|
+
Reply.all.select {|r| r.id == 1 }.size.should == 1
|
|
181
|
+
Reply.all.select {|r| r.id == 1 }.first.id.should == 1
|
|
182
|
+
lambda { Reply.select(:id).first.content }.should raise_error(ActiveRecord::MissingAttributeError)
|
|
183
|
+
end
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
describe "NameScope bug" do
|
|
187
|
+
context "group named_scope" do
|
|
188
|
+
it "should be equal to count(:group => '')" do
|
|
189
|
+
Reply.group('replies.topic_id').count.should == Reply.count(:group => 'replies.topic_id')
|
|
190
|
+
end
|
|
191
|
+
end
|
|
177
192
|
end
|
|
178
193
|
|
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: 63
|
|
5
5
|
prerelease: false
|
|
6
6
|
segments:
|
|
7
7
|
- 0
|
|
8
8
|
- 9
|
|
9
|
-
-
|
|
10
|
-
version: 0.9.
|
|
9
|
+
- 2
|
|
10
|
+
version: 0.9.2
|
|
11
11
|
platform: ruby
|
|
12
12
|
authors:
|
|
13
13
|
- Grant Ammons
|
|
@@ -15,12 +15,10 @@ autorequire:
|
|
|
15
15
|
bindir: bin
|
|
16
16
|
cert_chain: []
|
|
17
17
|
|
|
18
|
-
date: 2010-
|
|
18
|
+
date: 2010-12-10 00:00:00 -05:00
|
|
19
19
|
default_executable:
|
|
20
20
|
dependencies:
|
|
21
21
|
- !ruby/object:Gem::Dependency
|
|
22
|
-
name: activerecord
|
|
23
|
-
prerelease: false
|
|
24
22
|
requirement: &id001 !ruby/object:Gem::Requirement
|
|
25
23
|
none: false
|
|
26
24
|
requirements:
|
|
@@ -33,10 +31,10 @@ dependencies:
|
|
|
33
31
|
- 5
|
|
34
32
|
version: 2.3.5
|
|
35
33
|
type: :runtime
|
|
34
|
+
name: activerecord
|
|
35
|
+
prerelease: false
|
|
36
36
|
version_requirements: *id001
|
|
37
37
|
- !ruby/object:Gem::Dependency
|
|
38
|
-
name: rubyforge
|
|
39
|
-
prerelease: false
|
|
40
38
|
requirement: &id002 !ruby/object:Gem::Requirement
|
|
41
39
|
none: false
|
|
42
40
|
requirements:
|
|
@@ -49,10 +47,10 @@ dependencies:
|
|
|
49
47
|
- 4
|
|
50
48
|
version: 2.0.4
|
|
51
49
|
type: :development
|
|
50
|
+
name: rubyforge
|
|
51
|
+
prerelease: false
|
|
52
52
|
version_requirements: *id002
|
|
53
53
|
- !ruby/object:Gem::Dependency
|
|
54
|
-
name: hoe
|
|
55
|
-
prerelease: false
|
|
56
54
|
requirement: &id003 !ruby/object:Gem::Requirement
|
|
57
55
|
none: false
|
|
58
56
|
requirements:
|
|
@@ -65,6 +63,8 @@ dependencies:
|
|
|
65
63
|
- 2
|
|
66
64
|
version: 2.6.2
|
|
67
65
|
type: :development
|
|
66
|
+
name: hoe
|
|
67
|
+
prerelease: false
|
|
68
68
|
version_requirements: *id003
|
|
69
69
|
description: |-
|
|
70
70
|
* Tired of waiting for Rails 3 and its new super-sweet query interface? Try fake_arel!
|