whiny-mass-assignment 0.1.1 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,2 +1 @@
1
1
  gem 'rspec'
2
- gem 'zentest'
data/Manifest CHANGED
@@ -5,6 +5,7 @@ Manifest
5
5
  README.md
6
6
  Rakefile
7
7
  lib/whiny-mass-assignment.rb
8
+ lib/whiny-mass-assignment/color_escapes.rb
8
9
  lib/whiny-mass-assignment/configuration.rb
9
10
  lib/whiny-mass-assignment/sanitizer.rb
10
11
  lib/whiny_mass_assignment.rb
@@ -13,3 +14,4 @@ spec/config_spec.rb
13
14
  spec/sanitizer_spec.rb
14
15
  spec/spec_helper.rb
15
16
  tasks/spec.rake
17
+ whiny-mass-assignment.gemspec
data/README.md CHANGED
@@ -7,16 +7,22 @@ not a warning and should be treated as such. During development rails should rai
7
7
  it's obvious you're doing something you shouldn't. In production it is a security violation and should be
8
8
  available in an audit log.
9
9
 
10
+ ## Installation
11
+
12
+ gem "whiny-mass-assignment"
13
+
14
+ or as a plugin
15
+
16
+ rails plugin install git://github.com/appsinyourpants/whiny-mass-assignment.git
10
17
 
11
18
  ## Usage
12
19
 
13
- To enable whiny mass assignment errors simply set `whiny_mass_assignment` to `:raise` in your environment
14
- configuration.
20
+ To enable whiny mass assignment errors simply add the gem to your project. Once enabled, attempts to use
21
+ mass assignment on protected attributes will result in an exception.
15
22
 
16
- Application.configure do
17
- config.whiny_mass_assignment = :raise
18
- end
19
-
23
+ If you want to suppress the exceptions and only use the highlighted logging, add an initializer to the
24
+ project and set set `mode` to `:log`
25
+
26
+ # config/initializers/whiny-mass-assignment.rb
20
27
 
21
- Other options are `:log` and `:invalidate`. `:log` uses the default rails behavior while `:invalidate` will
22
- add a generic error message to the model validation errors in addition to the default log.
28
+ WhinyMassAssignment::Config.mode = :log
data/Rakefile CHANGED
@@ -2,13 +2,13 @@ require 'rubygems'
2
2
  require 'rake'
3
3
  require 'echoe'
4
4
 
5
- Echoe.new( 'whiny-mass-assignment', '0.1.1', ) do |p|
5
+ Echoe.new( 'whiny-mass-assignment', '0.1.3', ) do |p|
6
6
  p.description = "Complain loudly when protected attributes are set through mass assignment."
7
7
  p.url = "https://github.com/appsinyourpants/whiny-mass-assignment"
8
8
  p.author = "Paul Alexander"
9
9
  p.email = "paul@appsinyourpants.com"
10
10
  p.ignore_pattern = [ "tmp/*" ]
11
- p.development_dependencies = ["rspec"]
11
+ # p.development_dependencies = ["rspec"]
12
12
  end
13
13
 
14
14
 
@@ -0,0 +1,22 @@
1
+ COLOR_ESCAPES = {
2
+ :none => 0,
3
+ :bright => 1,
4
+ :black => 30,
5
+ :red => 31,
6
+ :green => 32,
7
+ :yellow => 33,
8
+ :blue => 34,
9
+ :magenta => 35,
10
+ :cyan => 36,
11
+ :white => 37,
12
+ :default => 39,
13
+ }
14
+
15
+
16
+ def c( clr, text = nil )
17
+ "\x1B[" + ( COLOR_ESCAPES[ clr ] || 0 ).to_s + 'm' + ( text ? text + "\x1B[0m" : "" )
18
+ end
19
+
20
+ def bc( clr, text = nil )
21
+ "\x1B[" + ( ( COLOR_ESCAPES[ clr ] || 0 ) + 10 ).to_s + 'm' + ( text ? text + "\x1B[0m" : "" )
22
+ end
@@ -6,7 +6,6 @@ module WhinyMassAssignment
6
6
  end
7
7
 
8
8
  def whiny_mass_assignment=(value)
9
- raise ArgumentError.new("invalid configuration value") unless %w{ log raise invalidate }.index(value.to_s)
10
9
  Config.mode = value
11
10
  end
12
11
 
@@ -1,3 +1,5 @@
1
+ require 'whiny-mass-assignment/color_escapes'
2
+
1
3
  module WhinyMassAssignment
2
4
  module Sanitizer
3
5
 
@@ -6,8 +8,8 @@ module WhinyMassAssignment
6
8
  end
7
9
 
8
10
  def warn!(attrs)
9
- super if Config.mode == :log
10
- whine! attrs if Config.mode == :raise
11
+ self.logger.debug "#{bc :yellow}Can't mass-assign protected attributes: #{attrs.join(', ')}#{bc :default}" if self.logger
12
+ whine!(attrs) if WhinyMassAssignment::Config.mode == :raise
11
13
  end
12
14
 
13
15
  end
@@ -6,6 +6,12 @@ module WhinyMassAssignment
6
6
  end
7
7
 
8
8
  def self.mode=(value)
9
+ value = case value when true then :raise
10
+ when false then :log
11
+ else value
12
+ end
13
+ raise ArgumentError.new("invalid configuration value") unless %w{ log raise invalidate }.index(value.to_s)
14
+
9
15
  @mode = value
10
16
  end
11
17
 
data/spec/config_spec.rb CHANGED
@@ -28,6 +28,16 @@ describe WhinyMassAssignment::Config do
28
28
  lambda{ Whiny::Application.whiny_mass_assignment = :none }.should raise_error
29
29
  end
30
30
 
31
+ it "should coerce false to :log" do
32
+ lambda{ Whiny::Application.whiny_mass_assignment = false }.should_not raise_error
33
+ Whiny::Application.whiny_mass_assignment.should be :log
34
+ end
35
+
36
+ it "should coerce true to :raise" do
37
+ lambda{ Whiny::Application.whiny_mass_assignment = true }.should_not raise_error
38
+ Whiny::Application.whiny_mass_assignment.should be :raise
39
+ end
40
+
31
41
  end
32
42
 
33
43
  end
@@ -9,6 +9,7 @@ end
9
9
  describe ActiveModel::MassAssignmentSecurity::WhiteList do
10
10
 
11
11
  before do
12
+ WhinyMassAssignment::Config.mode = :raise
12
13
  @whitelist = List.new()
13
14
  end
14
15
 
@@ -2,32 +2,28 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{whiny-mass-assignment}
5
- s.version = "0.1.1"
5
+ s.version = "0.1.3"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Paul Alexander"]
9
- s.date = %q{2011-02-22}
9
+ s.date = %q{2011-02-23}
10
10
  s.description = %q{Complain loudly when protected attributes are set through mass assignment.}
11
11
  s.email = %q{paul@appsinyourpants.com}
12
- s.extra_rdoc_files = ["LICENSE", "README.md", "lib/whiny-mass-assignment.rb", "lib/whiny-mass-assignment/configuration.rb", "lib/whiny-mass-assignment/sanitizer.rb", "lib/whiny_mass_assignment.rb", "tasks/spec.rake"]
13
- s.files = ["Gemfile", "Gemfile.lock", "LICENSE", "Manifest", "README.md", "Rakefile", "lib/whiny-mass-assignment.rb", "lib/whiny-mass-assignment/configuration.rb", "lib/whiny-mass-assignment/sanitizer.rb", "lib/whiny_mass_assignment.rb", "rails/init.rb", "spec/config_spec.rb", "spec/sanitizer_spec.rb", "spec/spec_helper.rb", "tasks/spec.rake", "whiny-mass-assignment.gemspec"]
12
+ s.extra_rdoc_files = ["LICENSE", "README.md", "lib/whiny-mass-assignment.rb", "lib/whiny-mass-assignment/color_escapes.rb", "lib/whiny-mass-assignment/configuration.rb", "lib/whiny-mass-assignment/sanitizer.rb", "lib/whiny_mass_assignment.rb", "tasks/spec.rake"]
13
+ s.files = ["Gemfile", "Gemfile.lock", "LICENSE", "Manifest", "README.md", "Rakefile", "lib/whiny-mass-assignment.rb", "lib/whiny-mass-assignment/color_escapes.rb", "lib/whiny-mass-assignment/configuration.rb", "lib/whiny-mass-assignment/sanitizer.rb", "lib/whiny_mass_assignment.rb", "rails/init.rb", "spec/config_spec.rb", "spec/sanitizer_spec.rb", "spec/spec_helper.rb", "tasks/spec.rake", "whiny-mass-assignment.gemspec"]
14
14
  s.homepage = %q{https://github.com/appsinyourpants/whiny-mass-assignment}
15
15
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Whiny-mass-assignment", "--main", "README.md"]
16
16
  s.require_paths = ["lib"]
17
17
  s.rubyforge_project = %q{whiny-mass-assignment}
18
- s.rubygems_version = %q{1.3.7}
18
+ s.rubygems_version = %q{1.5.2}
19
19
  s.summary = %q{Complain loudly when protected attributes are set through mass assignment.}
20
20
 
21
21
  if s.respond_to? :specification_version then
22
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
23
22
  s.specification_version = 3
24
23
 
25
24
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
26
- s.add_development_dependency(%q<rspec>, [">= 0"])
27
25
  else
28
- s.add_dependency(%q<rspec>, [">= 0"])
29
26
  end
30
27
  else
31
- s.add_dependency(%q<rspec>, [">= 0"])
32
28
  end
33
29
  end
metadata CHANGED
@@ -1,50 +1,31 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: whiny-mass-assignment
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 1
8
- - 1
9
- version: 0.1.1
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.3
5
+ prerelease:
10
6
  platform: ruby
11
- authors:
7
+ authors:
12
8
  - Paul Alexander
13
9
  autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
-
17
- date: 2011-02-22 00:00:00 -08:00
12
+ date: 2011-02-23 00:00:00.000000000 -08:00
18
13
  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
- - 0
30
- version: "0"
31
- type: :development
32
- version_requirements: *id001
14
+ dependencies: []
33
15
  description: Complain loudly when protected attributes are set through mass assignment.
34
16
  email: paul@appsinyourpants.com
35
17
  executables: []
36
-
37
18
  extensions: []
38
-
39
- extra_rdoc_files:
19
+ extra_rdoc_files:
40
20
  - LICENSE
41
21
  - README.md
42
22
  - lib/whiny-mass-assignment.rb
23
+ - lib/whiny-mass-assignment/color_escapes.rb
43
24
  - lib/whiny-mass-assignment/configuration.rb
44
25
  - lib/whiny-mass-assignment/sanitizer.rb
45
26
  - lib/whiny_mass_assignment.rb
46
27
  - tasks/spec.rake
47
- files:
28
+ files:
48
29
  - Gemfile
49
30
  - Gemfile.lock
50
31
  - LICENSE
@@ -52,6 +33,7 @@ files:
52
33
  - README.md
53
34
  - Rakefile
54
35
  - lib/whiny-mass-assignment.rb
36
+ - lib/whiny-mass-assignment/color_escapes.rb
55
37
  - lib/whiny-mass-assignment/configuration.rb
56
38
  - lib/whiny-mass-assignment/sanitizer.rb
57
39
  - lib/whiny_mass_assignment.rb
@@ -64,40 +46,32 @@ files:
64
46
  has_rdoc: true
65
47
  homepage: https://github.com/appsinyourpants/whiny-mass-assignment
66
48
  licenses: []
67
-
68
49
  post_install_message:
69
- rdoc_options:
50
+ rdoc_options:
70
51
  - --line-numbers
71
52
  - --inline-source
72
53
  - --title
73
54
  - Whiny-mass-assignment
74
55
  - --main
75
56
  - README.md
76
- require_paths:
57
+ require_paths:
77
58
  - lib
78
- required_ruby_version: !ruby/object:Gem::Requirement
59
+ required_ruby_version: !ruby/object:Gem::Requirement
79
60
  none: false
80
- requirements:
81
- - - ">="
82
- - !ruby/object:Gem::Version
83
- segments:
84
- - 0
85
- version: "0"
86
- required_rubygems_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ! '>='
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
66
  none: false
88
- requirements:
89
- - - ">="
90
- - !ruby/object:Gem::Version
91
- segments:
92
- - 1
93
- - 2
94
- version: "1.2"
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '1.2'
95
71
  requirements: []
96
-
97
72
  rubyforge_project: whiny-mass-assignment
98
- rubygems_version: 1.3.7
73
+ rubygems_version: 1.5.2
99
74
  signing_key:
100
75
  specification_version: 3
101
76
  summary: Complain loudly when protected attributes are set through mass assignment.
102
77
  test_files: []
103
-