safe_attributes 1.0.6 → 1.0.7
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/NEWS.rdoc +4 -0
- data/README.rdoc +7 -3
- data/VERSION +1 -1
- data/lib/safe_attributes.rb +5 -1
- data/safe_attributes.gemspec +8 -8
- data/spec/safe_attributes/safe_attributes_spec.rb +36 -2
- metadata +157 -162
data/NEWS.rdoc
CHANGED
data/README.rdoc
CHANGED
@@ -54,7 +54,7 @@ attempt to install it for you. This can result in an error like below.
|
|
54
54
|
ERROR: Error installing safe_attributes:
|
55
55
|
activemodel requires activesupport (= 3.0.3, runtime)
|
56
56
|
|
57
|
-
You can use this gem with activerecord and activesupport >= 3.0
|
57
|
+
You can use this gem with activerecord and activesupport >= 3.0.
|
58
58
|
If you already have an appropriate version of activerecord and
|
59
59
|
activesupport installed then use --ignore-dependencies to avoid this
|
60
60
|
error. If you have the latest version already then the gem should install
|
@@ -64,11 +64,15 @@ without issue using the recommended approach above.
|
|
64
64
|
|
65
65
|
=== Ruby
|
66
66
|
|
67
|
-
This gem has been tested
|
67
|
+
This gem has been tested with:
|
68
68
|
|
69
69
|
* Ruby 1.8.7
|
70
70
|
* Ruby 1.9.2
|
71
|
-
* JRuby 1.
|
71
|
+
* JRuby 1.6.4
|
72
|
+
|
73
|
+
Note that as of Sept. 25, 2011, jruby 1.6.4 failed some tests when using
|
74
|
+
ActiveRecord 3.1. Google indicates others have seen these issues so I
|
75
|
+
expect it will be addressed in the near future by a new jruby release.
|
72
76
|
|
73
77
|
=== Rails
|
74
78
|
Add safe_attributes to your Gemfile.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.
|
1
|
+
1.0.7
|
data/lib/safe_attributes.rb
CHANGED
@@ -54,7 +54,11 @@ module SafeAttributes
|
|
54
54
|
|
55
55
|
module InstanceMethods
|
56
56
|
def read_attribute_for_validation(attr)
|
57
|
-
self
|
57
|
+
if (self.attributes.include?(attr.to_s))
|
58
|
+
self[attr.to_sym]
|
59
|
+
else
|
60
|
+
self.send(attr.to_s) if (self.respond_to?(attr.to_sym))
|
61
|
+
end
|
58
62
|
end
|
59
63
|
end
|
60
64
|
|
data/safe_attributes.gemspec
CHANGED
@@ -4,14 +4,14 @@
|
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
|
-
s.name =
|
8
|
-
s.version = "1.0.
|
7
|
+
s.name = "safe_attributes"
|
8
|
+
s.version = "1.0.7"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Brian Jones"]
|
12
|
-
s.date =
|
13
|
-
s.description =
|
14
|
-
s.email =
|
12
|
+
s.date = "2011-11-18"
|
13
|
+
s.description = "Better support for legacy database schemas for ActiveRecord, such as columns named class, or any other name that conflicts with an instance method of ActiveRecord."
|
14
|
+
s.email = "cbj@gnu.org"
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"LICENSE",
|
17
17
|
"README.rdoc"
|
@@ -31,11 +31,11 @@ Gem::Specification.new do |s|
|
|
31
31
|
"spec/safe_attributes/safe_attributes_spec.rb",
|
32
32
|
"spec/spec_helper.rb"
|
33
33
|
]
|
34
|
-
s.homepage =
|
34
|
+
s.homepage = "http://github.com/bjones/safe_attributes"
|
35
35
|
s.licenses = ["MIT"]
|
36
36
|
s.require_paths = ["lib"]
|
37
|
-
s.rubygems_version =
|
38
|
-
s.summary =
|
37
|
+
s.rubygems_version = "1.8.11"
|
38
|
+
s.summary = "Useful for legacy database support, adds support for reserved word column names with ActiveRecord"
|
39
39
|
|
40
40
|
if s.respond_to? :specification_version then
|
41
41
|
s.specification_version = 3
|
@@ -12,6 +12,7 @@ ActiveRecord::Base.connection.create_table(:my_models) do |t|
|
|
12
12
|
t.string :errors
|
13
13
|
# support hyphenated column names
|
14
14
|
t.string :"comment-frequency"
|
15
|
+
t.string :attribute
|
15
16
|
end
|
16
17
|
|
17
18
|
class MyModel < ActiveRecord::Base
|
@@ -20,7 +21,23 @@ class MyModel < ActiveRecord::Base
|
|
20
21
|
validates_presence_of :class
|
21
22
|
end
|
22
23
|
|
23
|
-
|
24
|
+
ActiveRecord::Base.connection.execute("DROP TABLE IF EXISTS 'my_users'")
|
25
|
+
ActiveRecord::Base.connection.create_table(:my_users) do |t|
|
26
|
+
t.string :encrypted_password
|
27
|
+
end
|
28
|
+
|
29
|
+
class MyUser < ActiveRecord::Base
|
30
|
+
include SafeAttributes
|
31
|
+
attr_reader :password
|
32
|
+
def password=(p)
|
33
|
+
@password = p
|
34
|
+
self.encrypted_password = p
|
35
|
+
end
|
36
|
+
|
37
|
+
validates_presence_of :password
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "models" do
|
24
41
|
|
25
42
|
before(:each) do
|
26
43
|
ActiveRecord::Base.connection.increment_open_transactions
|
@@ -75,6 +92,16 @@ describe MyModel do
|
|
75
92
|
(@model.methods.include?('id') || @model.methods.include?(:id)).should be_true
|
76
93
|
end
|
77
94
|
|
95
|
+
it "does not defined attribute()" do
|
96
|
+
@model.respond_to?(:attribute) # to force method generation
|
97
|
+
(@model.methods.include?('attribute') || @model.methods.include?(:attribute)).should be_false
|
98
|
+
end
|
99
|
+
|
100
|
+
it "does not defined attribute=()" do
|
101
|
+
@model.respond_to?(:attribute=) # to force method generation
|
102
|
+
(@model.methods.include?('attribute=') || @model.methods.include?(:attribute=)).should be_false
|
103
|
+
end
|
104
|
+
|
78
105
|
it "can create instance in database with special attribute name" do
|
79
106
|
m = MyModel.create!(:class => 'Foo')
|
80
107
|
m = MyModel.find(m.id)
|
@@ -114,7 +141,7 @@ describe MyModel do
|
|
114
141
|
m.size.should == 0
|
115
142
|
end
|
116
143
|
|
117
|
-
it "validates presence of
|
144
|
+
it "validates presence of bad attribute name" do
|
118
145
|
@model.valid?.should be_false
|
119
146
|
Array(@model.errors[:class]).include?("can't be blank").should be_true
|
120
147
|
|
@@ -132,5 +159,12 @@ describe MyModel do
|
|
132
159
|
m.changed?.should be_true
|
133
160
|
end
|
134
161
|
|
162
|
+
it "validates presence of non-attribute" do
|
163
|
+
m = MyUser.new()
|
164
|
+
m.valid?.should be_false
|
165
|
+
m = MyUser.new({:password => 'foobar'})
|
166
|
+
m.valid?.should be_true
|
167
|
+
end
|
168
|
+
|
135
169
|
end
|
136
170
|
|
metadata
CHANGED
@@ -1,181 +1,176 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: safe_attributes
|
3
|
-
version: !ruby/object:Gem::Version
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.7
|
4
5
|
prerelease:
|
5
|
-
version: 1.0.6
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
8
|
-
|
7
|
+
authors:
|
8
|
+
- Brian Jones
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
12
|
+
date: 2011-11-18 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: activesupport
|
16
|
+
requirement: &70339699350360 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 3.0.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70339699350360
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: activerecord
|
27
|
+
requirement: &70339699349880 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 3.0.0
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70339699349880
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: jeweler
|
38
|
+
requirement: &70339699349380 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 1.5.2
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70339699349380
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rake
|
49
|
+
requirement: &70339699348900 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.8.7
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *70339699348900
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: rdoc
|
60
|
+
requirement: &70339699364800 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *70339699364800
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: &70339699364320 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: 2.3.0
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *70339699364320
|
80
|
+
- !ruby/object:Gem::Dependency
|
81
|
+
name: rcov
|
82
|
+
requirement: &70339699363840 !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ! '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
type: :development
|
89
|
+
prerelease: false
|
90
|
+
version_requirements: *70339699363840
|
91
|
+
- !ruby/object:Gem::Dependency
|
92
|
+
name: sqlite3
|
93
|
+
requirement: &70339699363360 !ruby/object:Gem::Requirement
|
94
|
+
none: false
|
95
|
+
requirements:
|
96
|
+
- - ! '>='
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: 1.3.4
|
99
|
+
type: :development
|
100
|
+
prerelease: false
|
101
|
+
version_requirements: *70339699363360
|
102
|
+
- !ruby/object:Gem::Dependency
|
103
|
+
name: activerecord-jdbcsqlite3-adapter
|
104
|
+
requirement: &70339699362880 !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
type: :development
|
111
|
+
prerelease: false
|
112
|
+
version_requirements: *70339699362880
|
113
|
+
- !ruby/object:Gem::Dependency
|
114
|
+
name: jruby-openssl
|
115
|
+
requirement: &70339699362360 !ruby/object:Gem::Requirement
|
116
|
+
none: false
|
117
|
+
requirements:
|
118
|
+
- - ! '>='
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
type: :development
|
122
|
+
prerelease: false
|
123
|
+
version_requirements: *70339699362360
|
124
|
+
description: Better support for legacy database schemas for ActiveRecord, such as
|
125
|
+
columns named class, or any other name that conflicts with an instance method of
|
126
|
+
ActiveRecord.
|
127
127
|
email: cbj@gnu.org
|
128
128
|
executables: []
|
129
|
-
|
130
129
|
extensions: []
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
- spec/spec_helper.rb
|
149
|
-
has_rdoc: true
|
130
|
+
extra_rdoc_files:
|
131
|
+
- LICENSE
|
132
|
+
- README.rdoc
|
133
|
+
files:
|
134
|
+
- .document
|
135
|
+
- .rspec
|
136
|
+
- Gemfile
|
137
|
+
- LICENSE
|
138
|
+
- NEWS.rdoc
|
139
|
+
- README.rdoc
|
140
|
+
- Rakefile
|
141
|
+
- VERSION
|
142
|
+
- lib/safe_attributes.rb
|
143
|
+
- lib/safe_attributes/railtie.rb
|
144
|
+
- safe_attributes.gemspec
|
145
|
+
- spec/safe_attributes/safe_attributes_spec.rb
|
146
|
+
- spec/spec_helper.rb
|
150
147
|
homepage: http://github.com/bjones/safe_attributes
|
151
|
-
licenses:
|
152
|
-
|
148
|
+
licenses:
|
149
|
+
- MIT
|
153
150
|
post_install_message:
|
154
151
|
rdoc_options: []
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
152
|
+
require_paths:
|
153
|
+
- lib
|
154
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
159
155
|
none: false
|
160
|
-
requirements:
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ! '>='
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
segments:
|
161
|
+
- 0
|
162
|
+
hash: -2431963502241220399
|
163
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
168
164
|
none: false
|
169
|
-
requirements:
|
170
|
-
|
171
|
-
|
172
|
-
|
165
|
+
requirements:
|
166
|
+
- - ! '>='
|
167
|
+
- !ruby/object:Gem::Version
|
168
|
+
version: '0'
|
173
169
|
requirements: []
|
174
|
-
|
175
170
|
rubyforge_project:
|
176
|
-
rubygems_version: 1.
|
171
|
+
rubygems_version: 1.8.11
|
177
172
|
signing_key:
|
178
173
|
specification_version: 3
|
179
|
-
summary: Useful for legacy database support, adds support for reserved word column
|
174
|
+
summary: Useful for legacy database support, adds support for reserved word column
|
175
|
+
names with ActiveRecord
|
180
176
|
test_files: []
|
181
|
-
|