accessible_attribute_matcher 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/README.md +52 -0
- data/Rakefile +5 -0
- data/accessible_attribute_matcher.gemspec +27 -0
- data/lib/accessible_attribute_matcher.rb +37 -0
- data/lib/accessible_attribute_matcher/version.rb +3 -0
- data/spec/matchers_spec.rb +9 -0
- data/spec/spec_helper.rb +15 -0
- data/spec/thing_spec.rb +10 -0
- metadata +140 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
AccessibleAttribute Matcher [![build status][status-image]][ci]
|
2
|
+
======================================================
|
3
|
+
|
4
|
+
About
|
5
|
+
-----
|
6
|
+
|
7
|
+
Use Rails 3 accessible_attributes reflection to test attr_accessible / attr_protected.
|
8
|
+
|
9
|
+
URLs:
|
10
|
+
|
11
|
+
- Github: https://github.com/bm5k/accessible_attribute_matcher/
|
12
|
+
- Documentation: http://rubydoc.info/github/BM5k/accessible_attribute_matcher/master/frames
|
13
|
+
- RubyGems: https://rubygems.org/gems/accessible_attribute_matcher
|
14
|
+
|
15
|
+
Installation
|
16
|
+
------------
|
17
|
+
|
18
|
+
Add to your Gemfile and run the `bundle` command to install it.
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
gem 'accessible_attribute_matcher'
|
22
|
+
```
|
23
|
+
|
24
|
+
**Requires Ruby 1.9.2 or later.**
|
25
|
+
|
26
|
+
Usage
|
27
|
+
-----
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
class Foo < ActiveRecord::Base
|
31
|
+
attr_accessible :field_a
|
32
|
+
attr_accessible :field_b, as: [:admin]
|
33
|
+
attr_protected :field_c
|
34
|
+
end
|
35
|
+
|
36
|
+
require 'spec_helper'
|
37
|
+
|
38
|
+
describe Foo do
|
39
|
+
|
40
|
+
it { should expose(:field_a) }
|
41
|
+
it { should_not expose(:field_b).to(:default) }
|
42
|
+
it { should expose(:field_b).to(:admin) }
|
43
|
+
it { should_not expose(:field_c) }
|
44
|
+
|
45
|
+
end
|
46
|
+
```
|
47
|
+
|
48
|
+
<!-- links -->
|
49
|
+
[ci]: http://travis-ci.org/BM5k/accessible_attribute_matcher "build status"
|
50
|
+
|
51
|
+
<!-- images -->
|
52
|
+
[status-image]: https://secure.travis-ci.org/BM5k/accessible_attribute_matcher.png?branch=master
|
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path('../lib', __FILE__)
|
3
|
+
require 'accessible_attribute_matcher/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = 'accessible_attribute_matcher'
|
7
|
+
s.version = AccessibleAttributeMatcher::VERSION
|
8
|
+
s.authors = ['BM5k']
|
9
|
+
s.email = ['me@bm5k.com']
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = 'RSpec matcher for ActiveModel accessible_attributes'
|
12
|
+
s.description = 'Use reflection to spec ActiveModel accessible_attributes'
|
13
|
+
|
14
|
+
s.rubyforge_project = 'accessible_attribute_matcher'
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ['lib']
|
20
|
+
|
21
|
+
s.add_dependency 'activemodel', '~> 3.2.0'
|
22
|
+
s.add_dependency 'activesupport', '~> 3.2.0'
|
23
|
+
s.add_dependency 'rspec', '~> 2.10.0'
|
24
|
+
|
25
|
+
s.add_development_dependency 'pry'
|
26
|
+
s.add_development_dependency 'pry-nav'
|
27
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'accessible_attribute_matcher/version'
|
2
|
+
|
3
|
+
module AccessibleAttributeMatcher
|
4
|
+
|
5
|
+
RSpec::Matchers.define :expose do |field|
|
6
|
+
|
7
|
+
chain(:to) { |r| @role = r }
|
8
|
+
|
9
|
+
# set the default role for accessible_attributes
|
10
|
+
def role
|
11
|
+
@role ||= :default
|
12
|
+
end
|
13
|
+
|
14
|
+
# simplify access to the described_class
|
15
|
+
def described_class
|
16
|
+
@described_class ||= actual.class
|
17
|
+
end
|
18
|
+
|
19
|
+
description do
|
20
|
+
"expose #{ field.inspect } to #{ role.inspect }"
|
21
|
+
end
|
22
|
+
|
23
|
+
failure_message_for_should do
|
24
|
+
"Expected #{ described_class } to expose #{ field.inspect } as #{ role.inspect }"
|
25
|
+
end
|
26
|
+
|
27
|
+
failure_message_for_should_not do
|
28
|
+
"Expected #{ described_class } not to expose #{ field.inspect } as #{ role.inspect }"
|
29
|
+
end
|
30
|
+
|
31
|
+
match do |actual|
|
32
|
+
described_class.accessible_attributes(role).include? field.to_sym
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
%w[ accessible_attribute_matcher active_support/core_ext active_model pry pry-nav ].each { |lib| require lib }
|
2
|
+
|
3
|
+
class Thing
|
4
|
+
|
5
|
+
extend ActiveModel::Naming
|
6
|
+
include ActiveModel::Conversion
|
7
|
+
include ActiveModel::MassAssignmentSecurity
|
8
|
+
|
9
|
+
attr_accessor :field_a, :field_b, :field_c
|
10
|
+
|
11
|
+
attr_accessible :field_a
|
12
|
+
attr_accessible :field_b, as: [:admin]
|
13
|
+
attr_protected :field_c
|
14
|
+
|
15
|
+
end
|
data/spec/thing_spec.rb
ADDED
metadata
ADDED
@@ -0,0 +1,140 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: accessible_attribute_matcher
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- BM5k
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-05-30 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: activemodel
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 3.2.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 3.2.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: activesupport
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 3.2.0
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 3.2.0
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rspec
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 2.10.0
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.10.0
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: pry
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: pry-nav
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
description: Use reflection to spec ActiveModel accessible_attributes
|
95
|
+
email:
|
96
|
+
- me@bm5k.com
|
97
|
+
executables: []
|
98
|
+
extensions: []
|
99
|
+
extra_rdoc_files: []
|
100
|
+
files:
|
101
|
+
- .gitignore
|
102
|
+
- .rspec
|
103
|
+
- .travis.yml
|
104
|
+
- Gemfile
|
105
|
+
- README.md
|
106
|
+
- Rakefile
|
107
|
+
- accessible_attribute_matcher.gemspec
|
108
|
+
- lib/accessible_attribute_matcher.rb
|
109
|
+
- lib/accessible_attribute_matcher/version.rb
|
110
|
+
- spec/matchers_spec.rb
|
111
|
+
- spec/spec_helper.rb
|
112
|
+
- spec/thing_spec.rb
|
113
|
+
homepage: ''
|
114
|
+
licenses: []
|
115
|
+
post_install_message:
|
116
|
+
rdoc_options: []
|
117
|
+
require_paths:
|
118
|
+
- lib
|
119
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
120
|
+
none: false
|
121
|
+
requirements:
|
122
|
+
- - ! '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
126
|
+
none: false
|
127
|
+
requirements:
|
128
|
+
- - ! '>='
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0'
|
131
|
+
requirements: []
|
132
|
+
rubyforge_project: accessible_attribute_matcher
|
133
|
+
rubygems_version: 1.8.23
|
134
|
+
signing_key:
|
135
|
+
specification_version: 3
|
136
|
+
summary: RSpec matcher for ActiveModel accessible_attributes
|
137
|
+
test_files:
|
138
|
+
- spec/matchers_spec.rb
|
139
|
+
- spec/spec_helper.rb
|
140
|
+
- spec/thing_spec.rb
|