attr_accessible_block 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/.rspec +1 -0
- data/README.md +6 -2
- data/lib/attr_accessible_block.rb +4 -7
- data/lib/attr_accessible_block/version.rb +1 -1
- data/spec/attr_accessible_block_spec.rb +13 -1
- metadata +8 -7
data/.gitignore
CHANGED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--backtrace
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
AttrAccessibleBlock 0.3.
|
1
|
+
AttrAccessibleBlock 0.3.1
|
2
2
|
=========================
|
3
3
|
|
4
4
|
[![travis-ci status](https://secure.travis-ci.org/dmitry/attr_accessible_block.png)](http://travis-ci.org/dmitry/attr_accessible_block)
|
@@ -87,10 +87,14 @@ Just add this code to the `config/initializers/plugins.rb` file:
|
|
87
87
|
|
88
88
|
ActiveModel::MassAssignmentSecurity::WhiteListBlock.always_accessible { user.admin? }
|
89
89
|
|
90
|
-
|
90
|
+
It works even with standard `attr_accessible`, look into specs to see behaviour.
|
91
|
+
|
92
|
+
> NOTE: if you are getting `stack level too deep` then you have recursive call of the model object in `always_accessible` or `add_variable` blocks. Try to avoid it.
|
91
93
|
|
92
94
|
Should be STI compatible, but haven't tested yet. Need's feedback on this feature. Feel free to contact with me if something goes wrong.
|
93
95
|
|
96
|
+
And there is more, you always still can use old implementation of the `attr_accessible`, just use `old_attr_accessible` method in your models.
|
97
|
+
|
94
98
|
For more answers on your questions you can look into tests and source code.
|
95
99
|
|
96
100
|
Used on http://tenerife.by
|
@@ -5,14 +5,11 @@ module ActiveModel::MassAssignmentSecurity
|
|
5
5
|
alias_method :old_attr_accessible, :attr_accessible
|
6
6
|
|
7
7
|
def attr_accessible(*attributes, &block)
|
8
|
-
|
9
|
-
class_attribute(:attr_accessible_block)
|
10
|
-
self.attr_accessible_block = block
|
8
|
+
class_attribute(:attr_accessible_block)
|
11
9
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
end
|
10
|
+
self.attr_accessible_block = (block_given? ? block : proc { add attributes })
|
11
|
+
|
12
|
+
include InstanceMethods
|
16
13
|
end
|
17
14
|
|
18
15
|
module InstanceMethods
|
@@ -29,8 +29,10 @@ class User < BaseModel
|
|
29
29
|
|
30
30
|
attr_accessible :email, :password, :date
|
31
31
|
|
32
|
+
@@user = User.new
|
33
|
+
|
32
34
|
def self.current
|
33
|
-
|
35
|
+
@@user
|
34
36
|
end
|
35
37
|
end
|
36
38
|
|
@@ -55,6 +57,16 @@ describe AttrAccessibleBlock do
|
|
55
57
|
user.role.should be_nil
|
56
58
|
end
|
57
59
|
|
60
|
+
it "should have standard static attr_accessible that always accessible" do
|
61
|
+
u = User.new.tap { |u| u.role = :admin }
|
62
|
+
User.should_receive(:current).twice.and_return(u)
|
63
|
+
user = User.new(:email => 'test@test.com', :password => 'test', 'date(i0)' => '10', :role => 'admin')
|
64
|
+
user.password.should eq 'test'
|
65
|
+
user.email.should eq 'test@test.com'
|
66
|
+
user.date.should eq '10'
|
67
|
+
user.role.should eq 'admin'
|
68
|
+
end
|
69
|
+
|
58
70
|
it "should have block attr_accessible" do
|
59
71
|
location = Location.new(:name => 'test', :size => 10, :user => 'user', 'point(i2)' => '10')
|
60
72
|
location.name.should eq 'test'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: attr_accessible_block
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2011-12-24 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activemodel
|
16
|
-
requirement: &
|
16
|
+
requirement: &8837640 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '3.1'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *8837640
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rspec
|
27
|
-
requirement: &
|
27
|
+
requirement: &8836740 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *8836740
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rake
|
38
|
-
requirement: &
|
38
|
+
requirement: &8834580 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *8834580
|
47
47
|
description: Set attr_accessible attributes on runtime.
|
48
48
|
email:
|
49
49
|
- dmitry.polushkin@gmail.com
|
@@ -52,6 +52,7 @@ extensions: []
|
|
52
52
|
extra_rdoc_files: []
|
53
53
|
files:
|
54
54
|
- .gitignore
|
55
|
+
- .rspec
|
55
56
|
- .travis.yml
|
56
57
|
- Gemfile
|
57
58
|
- Gemfile.lock
|