scopify 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/scopify/scope.rb +12 -7
- data/scopify.gemspec +1 -1
- data/spec/scopify_spec.rb +10 -0
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.3
|
data/lib/scopify/scope.rb
CHANGED
@@ -38,14 +38,19 @@ module Scopify
|
|
38
38
|
result = if @base.respond_to?(:scope_to_hash)
|
39
39
|
@base.scope_to_hash(@options)
|
40
40
|
else
|
41
|
-
@options.map do |
|
42
|
-
result = case
|
43
|
-
when :limit, :offset then
|
44
|
-
when :conditions
|
45
|
-
|
46
|
-
|
41
|
+
@options.map do |key, values|
|
42
|
+
result = case key
|
43
|
+
when :limit, :offset then values.min
|
44
|
+
when :conditions
|
45
|
+
if values.all?{|x| x.is_a?(Hash)}
|
46
|
+
values.inject({}){|hash, x| hash.merge(x)}
|
47
|
+
else
|
48
|
+
"(#{values * ") AND ("})"
|
49
|
+
end
|
50
|
+
when :order then values * ', '
|
51
|
+
else values
|
47
52
|
end
|
48
|
-
[
|
53
|
+
[key, result]
|
49
54
|
end
|
50
55
|
end
|
51
56
|
|
data/scopify.gemspec
CHANGED
data/spec/scopify_spec.rb
CHANGED
@@ -132,6 +132,16 @@ describe Scopify do
|
|
132
132
|
end
|
133
133
|
end
|
134
134
|
|
135
|
+
describe "default to_hash" do
|
136
|
+
it "merges conditions that are hashes" do
|
137
|
+
T1.scoped(:conditions => {:x=>true}).scoped(:conditions => {:y => true}).to_hash.should == {:conditions => {:x => true, :y => true}}
|
138
|
+
end
|
139
|
+
|
140
|
+
it "merges conditions that are strings" do
|
141
|
+
T1.scoped(:conditions => "x = 1").scoped(:conditions => "y = 1").to_hash.should == {:conditions => "(x = 1) AND (y = 1)"}
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
135
145
|
it "has a VERSION" do
|
136
146
|
Scopify::VERSION.should =~ /^\d+\.\d+\.\d+$/
|
137
147
|
end
|