fake_arel 1.4.0 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/fake_arel.gemspec +2 -2
- data/lib/fake_arel/extensions.rb +5 -0
- data/lib/fake_arel/rails_3_finders.rb +26 -0
- data/lib/fake_arel/with_scope_replacement.rb +1 -1
- data/spec/fake_arel_spec.rb +16 -0
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.5.0
|
data/fake_arel.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "fake_arel"
|
8
|
-
s.version = "1.
|
8
|
+
s.version = "1.5.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Grant Ammons"]
|
12
|
-
s.date = "
|
12
|
+
s.date = "2014-02-04"
|
13
13
|
s.description = "fake_arel will simulate rails 3 arel syntax for Rails 2."
|
14
14
|
s.email = "grant@pipelinedealsco.com"
|
15
15
|
s.extra_rdoc_files = [
|
data/lib/fake_arel/extensions.rb
CHANGED
@@ -60,6 +60,32 @@ module Rails3Finders
|
|
60
60
|
end
|
61
61
|
named_scope :or, __or_fn
|
62
62
|
|
63
|
+
# returns a new scope, having removed the options mentioned
|
64
|
+
# does *not* support extended scopes
|
65
|
+
def self.except(*options)
|
66
|
+
# include is renamed to includes in Rails 3
|
67
|
+
includes = options.delete(:includes)
|
68
|
+
options << :include if includes
|
69
|
+
|
70
|
+
new_options = (scope(:find) || {}).reject { |k, v| options.include?(k) }
|
71
|
+
with_exclusive_scope(:find => new_options) { scoped }
|
72
|
+
end
|
73
|
+
|
74
|
+
# returns a new scope, with just the order replaced
|
75
|
+
# does *not* support extended scopes
|
76
|
+
def self.reorder(*order)
|
77
|
+
new_options = (scope(:find) || {}).dup
|
78
|
+
new_options[:order] = order.flatten.join(',')
|
79
|
+
with_exclusive_scope(:find =>new_options) { scoped }
|
80
|
+
end
|
81
|
+
|
82
|
+
def self.pluck(column)
|
83
|
+
new_options = (scope(:find) || {}).dup
|
84
|
+
new_options[:select] = "#{quoted_table_name}.#{column}"
|
85
|
+
new_options.delete(:include)
|
86
|
+
with_exclusive_scope(:find => new_options) { all.map(&column) }
|
87
|
+
end
|
88
|
+
|
63
89
|
def self.fakearel_find_each(options = {:batch_size => 1000}, &block)
|
64
90
|
count = self.scoped({}).count
|
65
91
|
offset = 0
|
@@ -63,7 +63,7 @@ module WithScopeReplacement
|
|
63
63
|
hash[method][key] = merge_joins(params[key], hash[method][key])
|
64
64
|
# see https://rails.lighthouseapp.com/projects/8994/tickets/2810-with_scope-should-accept-and-use-order-option
|
65
65
|
# it works now in reverse order to comply with ActiveRecord 3
|
66
|
-
elsif
|
66
|
+
elsif [:group, :order].include?(key) && merge && !default_scoping.any?{ |s| s[method].keys.include?(key) }
|
67
67
|
hash[method][key] = [hash[method][key], params[key]].select{|o| !o.blank?}.join(', ')
|
68
68
|
else
|
69
69
|
hash[method][key] = hash[method][key] || params[key]
|
data/spec/fake_arel_spec.rb
CHANGED
@@ -95,6 +95,18 @@ describe "Fake Arel" do
|
|
95
95
|
Reply.group(:topic_id).map(&:topic_id).sort.should == [1, 2, 4].sort
|
96
96
|
end
|
97
97
|
|
98
|
+
it "should support pluck" do
|
99
|
+
Reply.where(:id => 5).pluck(:id).should == [5]
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should support reorder" do
|
103
|
+
Reply.where(:id => [4, 5]).order("id DESC").reorder("id").pluck(:id).should == [4, 5]
|
104
|
+
end
|
105
|
+
|
106
|
+
it "should support except" do
|
107
|
+
Reply.select(:id).except(:select).first.created_at.should_not == nil
|
108
|
+
end
|
109
|
+
|
98
110
|
it "should properly chain order scope in definitions" do
|
99
111
|
Reply.topic_4_id_asc.all.should == Reply.find(:all, :conditions => {:topic_id => 4}, :order=>'id asc')
|
100
112
|
Reply.topic_4_id_desc.all.should == Reply.find(:all, :conditions => {:topic_id => 4}, :order=>'id desc')
|
@@ -156,6 +168,10 @@ describe "Fake Arel" do
|
|
156
168
|
}
|
157
169
|
end
|
158
170
|
|
171
|
+
it "should properly chain with group" do
|
172
|
+
Topic.group(:john).group(:doe).scope(:find, :group).should == 'john, doe'
|
173
|
+
end
|
174
|
+
|
159
175
|
it "should respond to scoped" do
|
160
176
|
Reply.scoped({}).class.should == ActiveRecord::NamedScope::Scope
|
161
177
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fake_arel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2014-02-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
@@ -192,7 +192,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
192
192
|
version: '0'
|
193
193
|
segments:
|
194
194
|
- 0
|
195
|
-
hash:
|
195
|
+
hash: -1479168766933848698
|
196
196
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
197
197
|
none: false
|
198
198
|
requirements:
|