scoped_attr_accessible 0.1.3 → 0.1.4
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.
|
1
|
+
0.1.4
|
@@ -12,6 +12,24 @@ module ScopedAttrAccessible
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
+
GLOBAL_SCOPE_KEY = :_scoped_attr_accessible_sanitizer_scope
|
16
|
+
|
17
|
+
def self.current_sanitizer_scope
|
18
|
+
Thread.current[GLOBAL_SCOPE_KEY]
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.current_sanitizer_scope=(value)
|
22
|
+
Thread.current[GLOBAL_SCOPE_KEY] = value
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.with_sanitizer_scope(scope)
|
26
|
+
old_sanitizer_scope = self.current_sanitizer_scope
|
27
|
+
self.current_sanitizer_scope = scope
|
28
|
+
yield if block_given?
|
29
|
+
ensure
|
30
|
+
self.current_sanitizer_scope = old_sanitizer_scope
|
31
|
+
end
|
32
|
+
|
15
33
|
if defined?(Rails::Railtie)
|
16
34
|
class Railtie < Rails::Railtie
|
17
35
|
initializer "scoped_attr_accessible.setup" do
|
@@ -85,7 +85,7 @@ module ScopedAttrAccessible
|
|
85
85
|
module InstanceMethods
|
86
86
|
|
87
87
|
def current_sanitizer_scope
|
88
|
-
@current_sanitizer_scope || self.class.current_sanitizer_scope
|
88
|
+
@current_sanitizer_scope || self.class.current_sanitizer_scope || ScopedAttrAccessible.current_sanitizer_scope
|
89
89
|
end
|
90
90
|
|
91
91
|
def current_sanitizer_scope=(value)
|
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{scoped_attr_accessible}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.4"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Darcy Laycock", "Mario Visic"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-11-02}
|
13
13
|
s.description = %q{scoped_attr_accessible is a plugin that makes it easy to scope the `attr_accessible` and `attr_protected`
|
14
14
|
methods on any library using ActiveModel's MassAssignmentSecurity module.}
|
15
15
|
s.email = %q{team+darcy+mario@thefrontiergroup.com.au}
|
@@ -152,6 +152,17 @@ describe ScopedAttrAccessible::ActiveModelMixin do
|
|
152
152
|
subject_instance.current_sanitizer_scope.should == :class_level
|
153
153
|
end
|
154
154
|
|
155
|
+
it 'should fallback to the global scope if others aren\'t set' do
|
156
|
+
subject_instance.current_sanitizer_scope = nil
|
157
|
+
subject.current_sanitizer_scope = nil
|
158
|
+
called = false
|
159
|
+
ScopedAttrAccessible.with_sanitizer_scope :global_scope do
|
160
|
+
called = true
|
161
|
+
subject_instance.current_sanitizer_scope.should == :global_scope
|
162
|
+
end
|
163
|
+
called.should be_true
|
164
|
+
end
|
165
|
+
|
155
166
|
it 'should fallback to default if no scope is set' do
|
156
167
|
subject_instance.current_sanitizer_scope = nil
|
157
168
|
subject.current_sanitizer_scope = nil
|
@@ -12,4 +12,34 @@ describe ScopedAttrAccessible do
|
|
12
12
|
klass.new.should respond_to(:current_sanitizer_scope)
|
13
13
|
end
|
14
14
|
|
15
|
+
it 'should let you set the current global sanitizer scope permanently' do
|
16
|
+
begin
|
17
|
+
old = ScopedAttrAccessible.current_sanitizer_scope
|
18
|
+
ScopedAttrAccessible.current_sanitizer_scope = :a
|
19
|
+
ScopedAttrAccessible.current_sanitizer_scope.should == :a
|
20
|
+
ScopedAttrAccessible.current_sanitizer_scope = {:a => 1}
|
21
|
+
ScopedAttrAccessible.current_sanitizer_scope.should == {:a => 1}
|
22
|
+
ensure
|
23
|
+
ScopedAttrAccessible.current_sanitizer_scope = old
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should let you temporary replace the sanitizer scope' do
|
28
|
+
begin
|
29
|
+
old = ScopedAttrAccessible.current_sanitizer_scope
|
30
|
+
ScopedAttrAccessible.current_sanitizer_scope = :before_scope
|
31
|
+
ScopedAttrAccessible.current_sanitizer_scope.should == :before_scope
|
32
|
+
called = false
|
33
|
+
ScopedAttrAccessible.with_sanitizer_scope :between do
|
34
|
+
called = true
|
35
|
+
ScopedAttrAccessible.current_sanitizer_scope.should == :between
|
36
|
+
end
|
37
|
+
called.should == true
|
38
|
+
ScopedAttrAccessible.current_sanitizer_scope.should == :before_scope
|
39
|
+
ensure
|
40
|
+
ScopedAttrAccessible.current_sanitizer_scope = old
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
15
45
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scoped_attr_accessible
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 4
|
10
|
+
version: 0.1.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Darcy Laycock
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2010-
|
19
|
+
date: 2010-11-02 00:00:00 +08:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|