scoped_attr_accessible 0.1.0 → 0.1.2
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/.gitignore +2 -1
- data/README.md +12 -0
- data/Rakefile +6 -0
- data/VERSION +1 -1
- data/lib/scoped_attr_accessible.rb +8 -0
- data/lib/scoped_attr_accessible/sanitizer.rb +2 -1
- data/scoped_attr_accessible.gemspec +86 -0
- data/spec/scoped_attr_accessible/sanitizer_spec.rb +20 -0
- metadata +78 -6
data/.gitignore
CHANGED
@@ -1 +1,2 @@
|
|
1
|
-
coverage
|
1
|
+
coverage
|
2
|
+
pkg
|
data/README.md
CHANGED
@@ -45,6 +45,18 @@ at all, it will allow all variables except those marked as protected.
|
|
45
45
|
When declaring the scopes in the accessible / protected part, please note that they need to
|
46
46
|
be symbol names for simplicity's sake.
|
47
47
|
|
48
|
+
When you want to mark an attribute as accessible / protected in all scopes, you can use the `:all` scope.
|
49
|
+
For example:
|
50
|
+
|
51
|
+
class User < ActiveRecord::Base
|
52
|
+
attr_accessible :a, :scope => :all
|
53
|
+
attr_accessible :c, :scope => :admin
|
54
|
+
attr_accessible :b, :scope => :owner
|
55
|
+
end
|
56
|
+
|
57
|
+
Will allow `:admin` to access `:a` and `:c`, but not `:b`. Along the same lines, `:owner`
|
58
|
+
can access `:a` and `:b`, but not `:c`.
|
59
|
+
|
48
60
|
### Setting the Scope
|
49
61
|
|
50
62
|
Next, when you call methods that use mass assignment (e.g. `ActiveRecord::Base#attributes=`),
|
data/Rakefile
CHANGED
@@ -12,7 +12,13 @@ begin
|
|
12
12
|
gem.homepage = "http://github.com/thefrontiergroup/scoped_attr_accessible"
|
13
13
|
gem.authors = ["Darcy Laycock", "Mario Visic"]
|
14
14
|
gem.add_dependency "activemodel", "~> 3.0"
|
15
|
+
gem.add_dependency "activesupport", "~> 3.0"
|
15
16
|
gem.add_development_dependency "rspec", "~> 2.0"
|
17
|
+
gem.add_development_dependency "rr"
|
18
|
+
gem.add_development_dependency "ruby-debug"
|
19
|
+
gem.add_development_dependency "rcov"
|
20
|
+
gem.add_development_dependency "ZenTest"
|
21
|
+
|
16
22
|
end
|
17
23
|
Jeweler::GemcutterTasks.new
|
18
24
|
rescue LoadError
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.2
|
@@ -64,7 +64,8 @@ module ScopedAttrAccessible
|
|
64
64
|
def attribute_assignable_with_scope?(attribute, scope)
|
65
65
|
attribute = attribute.to_s.gsub(/\(.+/, '')
|
66
66
|
scope = scope.to_sym
|
67
|
-
scope_protected
|
67
|
+
scope_protected = @protected_attributes[scope] + @protected_attributes[:all]
|
68
|
+
scope_accessible = @accessible_attributes[scope] + @accessible_attributes[:all]
|
68
69
|
if scope_protected.include? attribute
|
69
70
|
return false
|
70
71
|
elsif scope_accessible.include?('all') || scope_accessible.include?(attribute)
|
@@ -0,0 +1,86 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{scoped_attr_accessible}
|
8
|
+
s.version = "0.1.2"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Darcy Laycock", "Mario Visic"]
|
12
|
+
s.date = %q{2010-10-13}
|
13
|
+
s.description = %q{scoped_attr_accessible is a plugin that makes it easy to scope the `attr_accessible` and `attr_protected`
|
14
|
+
methods on any library using ActiveModel's MassAssignmentSecurity module.}
|
15
|
+
s.email = %q{team+darcy+mario@thefrontiergroup.com.au}
|
16
|
+
s.extra_rdoc_files = [
|
17
|
+
"LICENSE",
|
18
|
+
"README.md"
|
19
|
+
]
|
20
|
+
s.files = [
|
21
|
+
".bundle/config",
|
22
|
+
".gitignore",
|
23
|
+
".rspec",
|
24
|
+
".rvmrc",
|
25
|
+
"Gemfile",
|
26
|
+
"Gemfile.lock",
|
27
|
+
"LICENSE",
|
28
|
+
"README.md",
|
29
|
+
"Rakefile",
|
30
|
+
"VERSION",
|
31
|
+
"autotest/discover.rb",
|
32
|
+
"lib/scoped_attr_accessible.rb",
|
33
|
+
"lib/scoped_attr_accessible/active_model_mixin.rb",
|
34
|
+
"lib/scoped_attr_accessible/sanitizer.rb",
|
35
|
+
"scoped_attr_accessible.gemspec",
|
36
|
+
"spec/scoped_attr_accessible/active_model_mixin_spec.rb",
|
37
|
+
"spec/scoped_attr_accessible/sanitizer_spec.rb",
|
38
|
+
"spec/scoped_attr_accessible_spec.rb",
|
39
|
+
"spec/spec_helper.rb",
|
40
|
+
"spec/support/custom_matchers.rb"
|
41
|
+
]
|
42
|
+
s.homepage = %q{http://github.com/thefrontiergroup/scoped_attr_accessible}
|
43
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
44
|
+
s.require_paths = ["lib"]
|
45
|
+
s.rubygems_version = %q{1.3.7}
|
46
|
+
s.summary = %q{Scoping for attr_accessible and attr_protected on ActiveModel objects.}
|
47
|
+
s.test_files = [
|
48
|
+
"spec/scoped_attr_accessible/active_model_mixin_spec.rb",
|
49
|
+
"spec/scoped_attr_accessible/sanitizer_spec.rb",
|
50
|
+
"spec/scoped_attr_accessible_spec.rb",
|
51
|
+
"spec/spec_helper.rb",
|
52
|
+
"spec/support/custom_matchers.rb"
|
53
|
+
]
|
54
|
+
|
55
|
+
if s.respond_to? :specification_version then
|
56
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
57
|
+
s.specification_version = 3
|
58
|
+
|
59
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
60
|
+
s.add_runtime_dependency(%q<activemodel>, ["~> 3.0"])
|
61
|
+
s.add_runtime_dependency(%q<activesupport>, ["~> 3.0"])
|
62
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.0"])
|
63
|
+
s.add_development_dependency(%q<rr>, [">= 0"])
|
64
|
+
s.add_development_dependency(%q<ruby-debug>, [">= 0"])
|
65
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
66
|
+
s.add_development_dependency(%q<ZenTest>, [">= 0"])
|
67
|
+
else
|
68
|
+
s.add_dependency(%q<activemodel>, ["~> 3.0"])
|
69
|
+
s.add_dependency(%q<activesupport>, ["~> 3.0"])
|
70
|
+
s.add_dependency(%q<rspec>, ["~> 2.0"])
|
71
|
+
s.add_dependency(%q<rr>, [">= 0"])
|
72
|
+
s.add_dependency(%q<ruby-debug>, [">= 0"])
|
73
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
74
|
+
s.add_dependency(%q<ZenTest>, [">= 0"])
|
75
|
+
end
|
76
|
+
else
|
77
|
+
s.add_dependency(%q<activemodel>, ["~> 3.0"])
|
78
|
+
s.add_dependency(%q<activesupport>, ["~> 3.0"])
|
79
|
+
s.add_dependency(%q<rspec>, ["~> 2.0"])
|
80
|
+
s.add_dependency(%q<rr>, [">= 0"])
|
81
|
+
s.add_dependency(%q<ruby-debug>, [">= 0"])
|
82
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
83
|
+
s.add_dependency(%q<ZenTest>, [">= 0"])
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
@@ -102,6 +102,26 @@ describe ScopedAttrAccessible::Sanitizer do
|
|
102
102
|
end
|
103
103
|
end
|
104
104
|
|
105
|
+
let :sanitizer_with_fallback do
|
106
|
+
ScopedAttrAccessible::Sanitizer.new.tap do |s|
|
107
|
+
s.make_accessible :a, :all
|
108
|
+
s.make_protected :b, :all
|
109
|
+
s.make_accessible :c, :default
|
110
|
+
s.make_accessible :d, :admin
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'should correctly handle sanitizers with fallback' do
|
115
|
+
sanitizer_with_fallback.should allow(:a, :default)
|
116
|
+
sanitizer_with_fallback.should allow(:a, :admin)
|
117
|
+
sanitizer_with_fallback.should_not allow(:b, :default)
|
118
|
+
sanitizer_with_fallback.should_not allow(:b, :admin)
|
119
|
+
sanitizer_with_fallback.should allow(:c, :default)
|
120
|
+
sanitizer_with_fallback.should_not allow(:c, :admin)
|
121
|
+
sanitizer_with_fallback.should_not allow(:d, :default)
|
122
|
+
sanitizer_with_fallback.should allow(:d, :admin)
|
123
|
+
end
|
124
|
+
|
105
125
|
it 'should return true by default an empty list' do
|
106
126
|
empty_sanitizer.should allow(:a)
|
107
127
|
empty_sanitizer.should allow(:b)
|
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: 31
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 2
|
10
|
+
version: 0.1.2
|
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-10-
|
19
|
+
date: 2010-10-13 00:00:00 +08:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|
@@ -35,9 +35,24 @@ dependencies:
|
|
35
35
|
type: :runtime
|
36
36
|
version_requirements: *id001
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
|
-
name:
|
38
|
+
name: activesupport
|
39
39
|
prerelease: false
|
40
40
|
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 7
|
46
|
+
segments:
|
47
|
+
- 3
|
48
|
+
- 0
|
49
|
+
version: "3.0"
|
50
|
+
type: :runtime
|
51
|
+
version_requirements: *id002
|
52
|
+
- !ruby/object:Gem::Dependency
|
53
|
+
name: rspec
|
54
|
+
prerelease: false
|
55
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
41
56
|
none: false
|
42
57
|
requirements:
|
43
58
|
- - ~>
|
@@ -48,7 +63,63 @@ dependencies:
|
|
48
63
|
- 0
|
49
64
|
version: "2.0"
|
50
65
|
type: :development
|
51
|
-
version_requirements: *
|
66
|
+
version_requirements: *id003
|
67
|
+
- !ruby/object:Gem::Dependency
|
68
|
+
name: rr
|
69
|
+
prerelease: false
|
70
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
hash: 3
|
76
|
+
segments:
|
77
|
+
- 0
|
78
|
+
version: "0"
|
79
|
+
type: :development
|
80
|
+
version_requirements: *id004
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: ruby-debug
|
83
|
+
prerelease: false
|
84
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
85
|
+
none: false
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
hash: 3
|
90
|
+
segments:
|
91
|
+
- 0
|
92
|
+
version: "0"
|
93
|
+
type: :development
|
94
|
+
version_requirements: *id005
|
95
|
+
- !ruby/object:Gem::Dependency
|
96
|
+
name: rcov
|
97
|
+
prerelease: false
|
98
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
99
|
+
none: false
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
hash: 3
|
104
|
+
segments:
|
105
|
+
- 0
|
106
|
+
version: "0"
|
107
|
+
type: :development
|
108
|
+
version_requirements: *id006
|
109
|
+
- !ruby/object:Gem::Dependency
|
110
|
+
name: ZenTest
|
111
|
+
prerelease: false
|
112
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
hash: 3
|
118
|
+
segments:
|
119
|
+
- 0
|
120
|
+
version: "0"
|
121
|
+
type: :development
|
122
|
+
version_requirements: *id007
|
52
123
|
description: |-
|
53
124
|
scoped_attr_accessible is a plugin that makes it easy to scope the `attr_accessible` and `attr_protected`
|
54
125
|
methods on any library using ActiveModel's MassAssignmentSecurity module.
|
@@ -75,6 +146,7 @@ files:
|
|
75
146
|
- lib/scoped_attr_accessible.rb
|
76
147
|
- lib/scoped_attr_accessible/active_model_mixin.rb
|
77
148
|
- lib/scoped_attr_accessible/sanitizer.rb
|
149
|
+
- scoped_attr_accessible.gemspec
|
78
150
|
- spec/scoped_attr_accessible/active_model_mixin_spec.rb
|
79
151
|
- spec/scoped_attr_accessible/sanitizer_spec.rb
|
80
152
|
- spec/scoped_attr_accessible_spec.rb
|