whiny_attr_accessible 0.0.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/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README +0 -0
- data/README.rdoc +17 -0
- data/Rakefile +30 -0
- data/VERSION +1 -0
- data/lib/mongo_mapper/accessible.rb +21 -0
- data/lib/mongo_mapper/print_diffs.rb +12 -0
- data/lib/mongo_mapper/protected.rb +21 -0
- data/lib/util/helpers.rb +9 -0
- data/lib/util/whiny_attr_accessible_error.rb +2 -0
- data/lib/whiny_attr_accessible.rb +6 -0
- data/spec/mongo_mapper/accessible_spec.rb +15 -0
- data/spec/mongo_mapper/protected_spec.rb +15 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +37 -0
- metadata +98 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Scott J. Tamosunas
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
File without changes
|
data/README.rdoc
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
= whiny_attr_accessible
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Note on Patches/Pull Requests
|
6
|
+
|
7
|
+
* Fork the project.
|
8
|
+
* Make your feature addition or bug fix.
|
9
|
+
* Add tests for it. This is important so I don't break it in a
|
10
|
+
future version unintentionally.
|
11
|
+
* Commit, do not mess with rakefile, version, or history.
|
12
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
13
|
+
* Send me a pull request. Bonus points for topic branches.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2010 Scott J. Tamosunas. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'rspec/core'
|
4
|
+
require 'rspec/core/rake_task'
|
5
|
+
require 'rspec'
|
6
|
+
|
7
|
+
begin
|
8
|
+
require 'jeweler'
|
9
|
+
Jeweler::Tasks.new do |gem|
|
10
|
+
gem.name = "whiny_attr_accessible"
|
11
|
+
gem.summary = %Q{Make attr_accessible and attr_protected throw exceptions in non-production mode}
|
12
|
+
gem.description = %Q{Make attr_accessible and attr_protected throw exceptions in non-production mode, yo.}
|
13
|
+
gem.email = "tamosunas@gmail.com"
|
14
|
+
gem.homepage = "http://github.com/scotttam/whiny_attr_accessible"
|
15
|
+
gem.authors = ["Scott J. Tamosunas"]
|
16
|
+
gem.add_development_dependency "rspec", ">= 1.2.9"
|
17
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
18
|
+
end
|
19
|
+
Jeweler::GemcutterTasks.new
|
20
|
+
rescue LoadError
|
21
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
22
|
+
end
|
23
|
+
|
24
|
+
RSpec::Core::RakeTask.new(:spec) do |t|
|
25
|
+
t.pattern = FileList['spec/**/*_spec.rb']
|
26
|
+
t.rcov = false
|
27
|
+
end
|
28
|
+
|
29
|
+
# task :spec => :check_dependencies
|
30
|
+
task :default => :spec
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
@@ -0,0 +1,21 @@
|
|
1
|
+
if development_or_test?
|
2
|
+
module MongoMapper
|
3
|
+
module Plugins
|
4
|
+
module Accessible
|
5
|
+
module InstanceMethods
|
6
|
+
include PrintDiffs
|
7
|
+
|
8
|
+
protected
|
9
|
+
|
10
|
+
def filter_inaccessible_attrs_with_exception(attrs)
|
11
|
+
safe_attrs = filter_inaccessible_attrs_without_exception(attrs)
|
12
|
+
check_and_raise_if_diffs(attrs, safe_attrs)
|
13
|
+
safe_attrs
|
14
|
+
end
|
15
|
+
|
16
|
+
my_alias_method_chain :filter_inaccessible_attrs, :exception
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module PrintDiffs
|
2
|
+
def check_and_raise_if_diffs(attrs, safe_attrs)
|
3
|
+
diff = attrs.flatten - safe_attrs.flatten
|
4
|
+
return if diff.blank?
|
5
|
+
results = []
|
6
|
+
diff.length.times do |idx|
|
7
|
+
next if idx % 2 != 0
|
8
|
+
results << "#{diff[idx]} => #{diff[idx + 1]}"
|
9
|
+
end
|
10
|
+
raise WhinyAttrAccessibleError.new("You tried to assign the following attributes that are either protected or not accessible: #{results.join(", ")}")
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
if development_or_test?
|
2
|
+
module MongoMapper
|
3
|
+
module Plugins
|
4
|
+
module Protected
|
5
|
+
module InstanceMethods
|
6
|
+
include PrintDiffs
|
7
|
+
|
8
|
+
protected
|
9
|
+
|
10
|
+
def filter_protected_attrs_with_exception(attrs)
|
11
|
+
safe_attrs = filter_protected_attrs_without_exception(attrs)
|
12
|
+
check_and_raise_if_diffs(attrs, safe_attrs)
|
13
|
+
safe_attrs
|
14
|
+
end
|
15
|
+
|
16
|
+
my_alias_method_chain :filter_protected_attrs, :exception
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/util/helpers.rb
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
def development_or_test?
|
2
|
+
return true unless defined?(Rails)
|
3
|
+
Rails.env.development? || Rails.env.test?
|
4
|
+
end
|
5
|
+
|
6
|
+
def my_alias_method_chain(original, aliased)
|
7
|
+
alias_method "#{original}_without_#{aliased}", original
|
8
|
+
alias_method original, "#{original}_with_#{aliased}"
|
9
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe "AttrAccessible" do
|
4
|
+
before(:each) do
|
5
|
+
@foo = Accessible.create!
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should raise an exception when trying to set an attribute that's not attr_accessible" do
|
9
|
+
lambda { @foo.update_attributes(:protected => "no") }.should raise_error(WhinyAttrAccessibleError)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should not raise an exception when setting an attribute that's accessible" do
|
13
|
+
lambda { @foo.update_attributes(:unprotected => "yes") }.should_not raise_error(WhinyAttrAccessibleError)
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe "Protected" do
|
4
|
+
before(:each) do
|
5
|
+
@foo = Protected.create!
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should raise an exception when trying to set an attribute that's attr_protected" do
|
9
|
+
lambda { @foo.update_attributes(:protected => "no") }.should raise_error(WhinyAttrAccessibleError)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should not raise an exception when setting an attribute that's not protected" do
|
13
|
+
lambda { @foo.update_attributes(:unprotected => "yes") }.should_not raise_error(WhinyAttrAccessibleError)
|
14
|
+
end
|
15
|
+
end
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
require 'mongo_mapper'
|
6
|
+
require 'rspec'
|
7
|
+
|
8
|
+
require 'whiny_attr_accessible'
|
9
|
+
|
10
|
+
Rspec.configure do |config|
|
11
|
+
config.mock_with :mocha
|
12
|
+
end
|
13
|
+
|
14
|
+
config = {
|
15
|
+
'test' => {'host' => 'localhost', 'port' => 27017, 'database' => 'mongoa_test'},
|
16
|
+
}
|
17
|
+
|
18
|
+
MongoMapper.config = config
|
19
|
+
MongoMapper.connect("test")
|
20
|
+
|
21
|
+
class Accessible
|
22
|
+
include MongoMapper::Document
|
23
|
+
|
24
|
+
attr_accessible :unprotected
|
25
|
+
|
26
|
+
key :unprotected, String
|
27
|
+
key :protected, String
|
28
|
+
end
|
29
|
+
|
30
|
+
class Protected
|
31
|
+
include MongoMapper::Document
|
32
|
+
|
33
|
+
attr_protected :protected
|
34
|
+
|
35
|
+
key :unprotected, String
|
36
|
+
key :protected, String
|
37
|
+
end
|
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: whiny_attr_accessible
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: 0.0.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Scott J. Tamosunas
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-10-29 00:00:00 -04:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: rspec
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 1
|
30
|
+
- 2
|
31
|
+
- 9
|
32
|
+
version: 1.2.9
|
33
|
+
type: :development
|
34
|
+
version_requirements: *id001
|
35
|
+
description: Make attr_accessible and attr_protected throw exceptions in non-production mode, yo.
|
36
|
+
email: tamosunas@gmail.com
|
37
|
+
executables: []
|
38
|
+
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files:
|
42
|
+
- LICENSE
|
43
|
+
- README
|
44
|
+
- README.rdoc
|
45
|
+
files:
|
46
|
+
- .document
|
47
|
+
- .gitignore
|
48
|
+
- LICENSE
|
49
|
+
- README
|
50
|
+
- README.rdoc
|
51
|
+
- Rakefile
|
52
|
+
- VERSION
|
53
|
+
- lib/mongo_mapper/accessible.rb
|
54
|
+
- lib/mongo_mapper/print_diffs.rb
|
55
|
+
- lib/mongo_mapper/protected.rb
|
56
|
+
- lib/util/helpers.rb
|
57
|
+
- lib/util/whiny_attr_accessible_error.rb
|
58
|
+
- lib/whiny_attr_accessible.rb
|
59
|
+
- spec/mongo_mapper/accessible_spec.rb
|
60
|
+
- spec/mongo_mapper/protected_spec.rb
|
61
|
+
- spec/spec.opts
|
62
|
+
- spec/spec_helper.rb
|
63
|
+
has_rdoc: true
|
64
|
+
homepage: http://github.com/scotttam/whiny_attr_accessible
|
65
|
+
licenses: []
|
66
|
+
|
67
|
+
post_install_message:
|
68
|
+
rdoc_options:
|
69
|
+
- --charset=UTF-8
|
70
|
+
require_paths:
|
71
|
+
- lib
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
segments:
|
78
|
+
- 0
|
79
|
+
version: "0"
|
80
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
segments:
|
86
|
+
- 0
|
87
|
+
version: "0"
|
88
|
+
requirements: []
|
89
|
+
|
90
|
+
rubyforge_project:
|
91
|
+
rubygems_version: 1.3.7
|
92
|
+
signing_key:
|
93
|
+
specification_version: 3
|
94
|
+
summary: Make attr_accessible and attr_protected throw exceptions in non-production mode
|
95
|
+
test_files:
|
96
|
+
- spec/mongo_mapper/accessible_spec.rb
|
97
|
+
- spec/mongo_mapper/protected_spec.rb
|
98
|
+
- spec/spec_helper.rb
|