mass_assignment_assertions 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/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in mass_assignment_assertions.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,24 @@
1
+ Mass Assignment Assertions
2
+ ==========================
3
+
4
+ Rails Unit Test Assertions for ensuring attributes are marked protected.
5
+
6
+
7
+ Usage
8
+ -----
9
+
10
+ Add to `Gemfile`:
11
+
12
+ group :test do
13
+ gem 'mass_assignment_assertions'
14
+ end
15
+
16
+ Then in your unit tests:
17
+
18
+ def test_attrs_protected
19
+ assert_attr_protected Model, :user_id, :post_id
20
+ end
21
+
22
+ The `assert_attr_protected` takes either a model class or an instance of a model.
23
+
24
+
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ task :default => :test
5
+ Rake::TestTask.new do |t|
6
+ t.libs << %w[test lib]
7
+ t.pattern = 'test/*_test.rb'
8
+ t.warning = true
9
+ t.verbose = true
10
+ end
11
+
@@ -0,0 +1,21 @@
1
+ module ActiveSupport
2
+ module Testing
3
+ module Assertions
4
+ def assert_attr_protected(model, *attributes)
5
+ model = model.class unless model.respond_to?(:protected_attributes)
6
+
7
+ attributes.each do |attribute|
8
+ if model.accessible_attributes.any?
9
+ assert_not_includes model.accessible_attributes, attribute
10
+ else
11
+ assert_includes model.protected_attributes, attribute
12
+ end
13
+ end
14
+
15
+ rescue NoMethodError
16
+ raise ArgumentError.new('must supply a model class or instance')
17
+ end
18
+ end
19
+ end
20
+ end
21
+
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "mass_assignment_assertions"
6
+ s.version = '0.0.1'
7
+ s.authors = ["mikeycgto"]
8
+ s.email = ["mikeycgto@gmail.com"]
9
+ s.homepage = "http://github.com/mikeycgto/mass_assignment_assertions"
10
+ s.summary = %q{Rails Unit Test Assertions for ensuring attributes are marked protected}
11
+ s.description = %q{Them gem will add assertions for ensuring attributes are marked protected}
12
+
13
+ s.rubyforge_project = "mass_assignment_assertions"
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ s.require_paths = ["lib"]
19
+
20
+ # specify any dependencies here; for example:
21
+ s.add_development_dependency "active_support"
22
+ s.add_development_dependency "active_model"
23
+ end
@@ -0,0 +1,54 @@
1
+ require 'minitest/autorun'
2
+ require 'active_support'
3
+ require 'active_model'
4
+
5
+ require 'mass_assignment_assertions'
6
+ require 'models'
7
+
8
+ class TestMassAssignmentAssertions < ActiveSupport::TestCase
9
+ def test_empty_model
10
+ assert_raises(MiniTest::Assertion) do
11
+ assert_attr_protected EmptyModel, :attribute
12
+ end
13
+ end
14
+
15
+ def test_empty_model_instance
16
+ assert_raises(MiniTest::Assertion) do
17
+ assert_attr_protected EmptyModel.new, :attribute
18
+ end
19
+ end
20
+
21
+ def test_accessible_model
22
+ assert_raises(MiniTest::Assertion) do
23
+ assert_attr_protected AccessibleModel, :user_name, :post_title
24
+ end
25
+ # these attributes are protected implicitly (WhiteList)
26
+ assert_attr_protected AccessibleModel, :user_id, :post_id
27
+ end
28
+
29
+ def test_accessible_model_instance
30
+ object = AccessibleModel.new
31
+
32
+ assert_raises(MiniTest::Assertion) do
33
+ assert_attr_protected object, :user_name, :post_title
34
+ end
35
+ # these attributes are protected implicitly (WhiteList)
36
+ assert_attr_protected object, :user_id, :post_id
37
+ end
38
+
39
+ def test_protected_model
40
+ assert_attr_protected ProtectedModel, :user_id, :post_id
41
+ end
42
+
43
+ def test_protected_model_instance
44
+ assert_attr_protected ProtectedModel.new, :user_id, :post_id
45
+ end
46
+
47
+ def test_not_a_model
48
+ assert_attr_protected Class.new, :attribute
49
+ fail 'test not model failed'
50
+
51
+ rescue Exception => e
52
+ assert_match(/must supply a model class or instance/, e.message)
53
+ end
54
+ end
data/test/models.rb ADDED
@@ -0,0 +1,15 @@
1
+ class ModelBase
2
+ include ActiveModel::MassAssignmentSecurity
3
+ end
4
+
5
+ class EmptyModel < ModelBase
6
+ end
7
+
8
+ class AccessibleModel < ModelBase
9
+ attr_accessible :user_name, :post_title
10
+ end
11
+
12
+ class ProtectedModel < ModelBase
13
+ attr_protected :user_id, :post_id
14
+ end
15
+
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mass_assignment_assertions
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - mikeycgto
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-04-27 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: active_support
16
+ requirement: &14302220 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *14302220
25
+ - !ruby/object:Gem::Dependency
26
+ name: active_model
27
+ requirement: &14301760 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *14301760
36
+ description: Them gem will add assertions for ensuring attributes are marked protected
37
+ email:
38
+ - mikeycgto@gmail.com
39
+ executables: []
40
+ extensions: []
41
+ extra_rdoc_files: []
42
+ files:
43
+ - .gitignore
44
+ - Gemfile
45
+ - README.md
46
+ - Rakefile
47
+ - lib/mass_assignment_assertions.rb
48
+ - mass_assignment_assertions.gemspec
49
+ - test/mass_assigment_assertions_test.rb
50
+ - test/models.rb
51
+ homepage: http://github.com/mikeycgto/mass_assignment_assertions
52
+ licenses: []
53
+ post_install_message:
54
+ rdoc_options: []
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ requirements: []
70
+ rubyforge_project: mass_assignment_assertions
71
+ rubygems_version: 1.8.10
72
+ signing_key:
73
+ specification_version: 3
74
+ summary: Rails Unit Test Assertions for ensuring attributes are marked protected
75
+ test_files: []