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 CHANGED
@@ -1 +1 @@
1
- 0.1.2
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 |k,v|
42
- result = case k
43
- when :limit, :offset then v.min
44
- when :conditions then "(#{v * ") AND ("})"
45
- when :order then v * ', '
46
- else v
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
- [k, result]
53
+ [key, result]
49
54
  end
50
55
  end
51
56
 
data/scopify.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{scopify}
8
- s.version = "0.1.2"
8
+ s.version = "0.1.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Michael Grosser"]
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
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 2
9
- version: 0.1.2
8
+ - 3
9
+ version: 0.1.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - Michael Grosser