context_aware_scope 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/context_aware_scope.gemspec +2 -2
- data/lib/context_aware_scope.rb +1 -1
- data/test/models.rb +2 -0
- data/test/units/default_scope_test.rb +17 -1
- data/test/units/readme_sample_test.rb +1 -1
- metadata +4 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
data/context_aware_scope.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{context_aware_scope}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Simplificator", "Fabio Kuhn"]
|
12
|
-
s.date = %q{2010-08-
|
12
|
+
s.date = %q{2010-08-27}
|
13
13
|
s.description = %q{Allows to add a context to a named_scope that will be passed through the whole scope chain}
|
14
14
|
s.email = %q{info@simplificator.com}
|
15
15
|
s.extra_rdoc_files = [
|
data/lib/context_aware_scope.rb
CHANGED
@@ -18,7 +18,7 @@ module ContextAwareScope
|
|
18
18
|
recursive_context
|
19
19
|
else
|
20
20
|
# add default scope context if on active_record
|
21
|
-
default_scoping.inject(@context){|context, scope| context.keep_merge(scope[:find][:context])}
|
21
|
+
default_scoping.inject(@context){|context, scope| context.keep_merge(scope[:find][:context] || {})}
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
data/test/models.rb
CHANGED
@@ -21,6 +21,8 @@ class City < ActiveRecord::Base
|
|
21
21
|
end
|
22
22
|
|
23
23
|
class Product < ActiveRecord::Base
|
24
|
+
default_scope :order => 'product.id ASC'
|
25
|
+
|
24
26
|
named_scope :luxurious, :conditions => ['price > ?', 100], :context => {:price => 'luxurious'}
|
25
27
|
named_scope :recent, :conditions => ['created_at > ?', 1.week.ago], :context => {:created_at => 'brand new'}
|
26
28
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
3
|
class DefaultScopeTest < Test::Unit::TestCase
|
4
|
-
context '
|
4
|
+
context 'a model' do
|
5
5
|
setup do
|
6
6
|
seed_models
|
7
7
|
end
|
@@ -37,5 +37,21 @@ class DefaultScopeTest < Test::Unit::TestCase
|
|
37
37
|
assert_equal ({:order => 'name asc', :name => 'Basel'}), @cities.context
|
38
38
|
end
|
39
39
|
end
|
40
|
+
|
41
|
+
context 'with a default scope without context' do
|
42
|
+
setup do
|
43
|
+
@products = Product.scoped({})
|
44
|
+
end
|
45
|
+
|
46
|
+
should 'should have results' do
|
47
|
+
assert_equal 2, @products.count
|
48
|
+
end
|
49
|
+
|
50
|
+
should 'have context on list' do
|
51
|
+
assert_equal ActiveRecord::NamedScope::Scope, @products.class
|
52
|
+
assert_equal Hash, @products.context.class
|
53
|
+
assert_equal ({}), @products.context
|
54
|
+
end
|
55
|
+
end
|
40
56
|
end
|
41
57
|
end
|
@@ -10,7 +10,7 @@ class ReadmeSampleTest < Test::Unit::TestCase
|
|
10
10
|
should 'should have results' do
|
11
11
|
assert_equal 1, @products.count
|
12
12
|
assert_equal ({:price => 'luxurious', :created_at => 'brand new'}), @products.context
|
13
|
-
assert_equal "You are looking at brand new and luxurious products", "You are looking at #{@products.context.values.to_sentence} products"
|
13
|
+
assert_equal "You are looking at brand new and luxurious products", "You are looking at #{@products.context.values.sort.to_sentence} products"
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: context_aware_scope
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Simplificator
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2010-08-
|
19
|
+
date: 2010-08-27 00:00:00 +02:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|