convenient_scopes 0.8.0 → 0.8.1
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/VERSION +1 -1
- data/convenient_scopes.gemspec +2 -2
- data/lib/convenient_scopes.rb +7 -2
- data/test/helper.rb +9 -1
- data/test/test_associations.rb +4 -0
- data/test/test_search_with_hash.rb +4 -0
- metadata +4 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.8.
|
1
|
+
0.8.1
|
data/convenient_scopes.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{convenient_scopes}
|
8
|
-
s.version = "0.8.
|
8
|
+
s.version = "0.8.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Ivan Schneider"]
|
12
|
-
s.date = %q{2011-07-
|
12
|
+
s.date = %q{2011-07-16}
|
13
13
|
s.description = %q{Dynamic scopes by convention for ActiveRecord 3}
|
14
14
|
s.email = %q{isc@massivebraingames.com}
|
15
15
|
s.extra_rdoc_files = [
|
data/lib/convenient_scopes.rb
CHANGED
@@ -16,7 +16,7 @@ module ConvenientScopes
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def search search_scopes
|
19
|
-
res =
|
19
|
+
res = scoped
|
20
20
|
search_scopes.each do |name, args|
|
21
21
|
if scopes.keys.include?(name.to_sym) || !respond_to?(name)
|
22
22
|
res = res.send name, args unless args == false
|
@@ -154,13 +154,18 @@ module ConvenientScopes
|
|
154
154
|
def convert_to_scope_arg scope_data
|
155
155
|
return scope_data unless scope_data.is_a? Array
|
156
156
|
relation_or_proc = scope_data.pop
|
157
|
-
joins_arg =
|
157
|
+
joins_arg = determine_joins_arg scope_data
|
158
158
|
if relation_or_proc.is_a? ActiveRecord::Relation
|
159
159
|
relation_or_proc.joins joins_arg
|
160
160
|
else
|
161
161
|
lambda {|*value| relation_or_proc.call(*value).joins joins_arg }
|
162
162
|
end
|
163
163
|
end
|
164
|
+
|
165
|
+
def determine_joins_arg scope_data
|
166
|
+
return scope_data.first if scope_data.size == 1
|
167
|
+
{scope_data.shift => determine_joins_arg(scope_data)}
|
168
|
+
end
|
164
169
|
|
165
170
|
end
|
166
171
|
|
data/test/helper.rb
CHANGED
@@ -18,10 +18,14 @@ class Group < ActiveRecord::Base
|
|
18
18
|
end
|
19
19
|
class Comment < ActiveRecord::Base
|
20
20
|
belongs_to :user
|
21
|
+
belongs_to :post
|
21
22
|
end
|
22
23
|
class UserProfile < ActiveRecord::Base
|
23
24
|
has_one :user
|
24
25
|
end
|
26
|
+
class Post < ActiveRecord::Base
|
27
|
+
has_many :comments
|
28
|
+
end
|
25
29
|
|
26
30
|
class Test::Unit::TestCase
|
27
31
|
def teardown
|
@@ -46,7 +50,7 @@ ActiveRecord::Schema.define(:version => 1) do
|
|
46
50
|
end
|
47
51
|
create_table :comments do |t|
|
48
52
|
t.string :body
|
49
|
-
t.integer :user_id
|
53
|
+
t.integer :user_id, :post_id
|
50
54
|
t.boolean :published
|
51
55
|
t.timestamps
|
52
56
|
end
|
@@ -54,4 +58,8 @@ ActiveRecord::Schema.define(:version => 1) do
|
|
54
58
|
t.date :birthdate
|
55
59
|
t.string :email
|
56
60
|
end
|
61
|
+
create_table :posts do |t|
|
62
|
+
t.string :title, :author
|
63
|
+
t.text :body
|
64
|
+
end
|
57
65
|
end
|
data/test/test_associations.rb
CHANGED
@@ -43,6 +43,10 @@ class TestAssociations < Test::Unit::TestCase
|
|
43
43
|
assert_equal [@dev_group], Group.users_comments_published
|
44
44
|
end
|
45
45
|
|
46
|
+
should "also handle three levels of association" do
|
47
|
+
assert_equal 3, Post.comments_user_user_profile_email_is('blbabla').to_sql.scan('INNER JOIN').size
|
48
|
+
end
|
49
|
+
|
46
50
|
should "be able to leverage a named scope on an association" do
|
47
51
|
Comment.scope :recent, Comment.created_at_after(1.hour.ago).created_at_not_nil
|
48
52
|
assert_equal [@slim], User.comments_recent
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: convenient_scopes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 61
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 8
|
9
|
-
-
|
10
|
-
version: 0.8.
|
9
|
+
- 1
|
10
|
+
version: 0.8.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Ivan Schneider
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-07-
|
18
|
+
date: 2011-07-16 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|