safe_attributes 1.0.4 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +8 -1
- data/NEWS.rdoc +15 -0
- data/README.rdoc +5 -2
- data/Rakefile +3 -2
- data/VERSION +1 -1
- data/lib/safe_attributes.rb +9 -0
- data/safe_attributes.gemspec +13 -8
- data/spec/safe_attributes/safe_attributes_spec.rb +28 -1
- metadata +109 -118
data/Gemfile
CHANGED
@@ -6,7 +6,14 @@ gem 'activerecord', '~> 3.0.0'
|
|
6
6
|
group :development do
|
7
7
|
gem 'jeweler', '>= 1.5.2'
|
8
8
|
gem 'rake', '>= 0.8.7'
|
9
|
+
gem 'rdoc'
|
9
10
|
gem 'rspec', '>= 2.3.0'
|
10
11
|
gem 'rcov'
|
11
|
-
|
12
|
+
platform :ruby do
|
13
|
+
gem 'sqlite3-ruby'
|
14
|
+
end
|
15
|
+
platform :jruby do
|
16
|
+
gem 'activerecord-jdbcsqlite3-adapter'
|
17
|
+
gem 'jruby-openssl'
|
18
|
+
end
|
12
19
|
end
|
data/NEWS.rdoc
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
= Version 1.0.5
|
2
|
+
|
3
|
+
* Resolved issues with columns named 'changed' and 'errors'
|
4
|
+
|
5
|
+
= Version 1.0.4
|
6
|
+
|
7
|
+
* Tested against Ruby 1.9.2, found and fixed an issue with default
|
8
|
+
bad attribute name list
|
9
|
+
* Tested against JRuby 1.5.6, found no issues
|
10
|
+
|
11
|
+
= Version 1.0.3
|
12
|
+
|
13
|
+
* Added validations support that should work with ActiveModel validators
|
14
|
+
by default
|
15
|
+
|
data/README.rdoc
CHANGED
@@ -64,8 +64,11 @@ without issue using the recommended approach above.
|
|
64
64
|
|
65
65
|
=== Ruby
|
66
66
|
|
67
|
-
|
68
|
-
|
67
|
+
This gem has been tested to work with:
|
68
|
+
|
69
|
+
* Ruby 1.8.7
|
70
|
+
* Ruby 1.9.2
|
71
|
+
* JRuby 1.5.6
|
69
72
|
|
70
73
|
=== Rails
|
71
74
|
Add safe_attributes to your Gemfile.
|
data/Rakefile
CHANGED
@@ -35,10 +35,11 @@ end
|
|
35
35
|
|
36
36
|
task :default => :spec
|
37
37
|
|
38
|
-
require '
|
39
|
-
|
38
|
+
require 'rdoc/task'
|
39
|
+
RDoc::Task.new do |rdoc|
|
40
40
|
rdoc.rdoc_dir = 'rdoc'
|
41
41
|
rdoc.title = "SafeAttributes #{version}"
|
42
42
|
rdoc.rdoc_files.include('README*')
|
43
|
+
rdoc.rdoc_files.include('NEWS*')
|
43
44
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
44
45
|
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.
|
1
|
+
1.0.5
|
data/lib/safe_attributes.rb
CHANGED
@@ -41,6 +41,15 @@ module SafeAttributes
|
|
41
41
|
return if (bad_attribute_names.include?(method.to_sym))
|
42
42
|
super(attr_name)
|
43
43
|
end
|
44
|
+
|
45
|
+
def instance_method_already_implemented?(method_name)
|
46
|
+
begin
|
47
|
+
return super(method_name)
|
48
|
+
rescue ActiveRecord::DangerousAttributeError
|
49
|
+
return true
|
50
|
+
end
|
51
|
+
return false
|
52
|
+
end
|
44
53
|
end
|
45
54
|
|
46
55
|
module InstanceMethods
|
data/safe_attributes.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{safe_attributes}
|
8
|
-
s.version = "1.0.
|
8
|
+
s.version = "1.0.5"
|
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 = %q{2011-
|
12
|
+
s.date = %q{2011-07-18}
|
13
13
|
s.description = %q{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
14
|
s.email = %q{cbj@gnu.org}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -21,6 +21,7 @@ Gem::Specification.new do |s|
|
|
21
21
|
".rspec",
|
22
22
|
"Gemfile",
|
23
23
|
"LICENSE",
|
24
|
+
"NEWS.rdoc",
|
24
25
|
"README.rdoc",
|
25
26
|
"Rakefile",
|
26
27
|
"VERSION",
|
@@ -33,15 +34,10 @@ Gem::Specification.new do |s|
|
|
33
34
|
s.homepage = %q{http://github.com/bjones/safe_attributes}
|
34
35
|
s.licenses = ["MIT"]
|
35
36
|
s.require_paths = ["lib"]
|
36
|
-
s.rubygems_version = %q{1.
|
37
|
+
s.rubygems_version = %q{1.6.2}
|
37
38
|
s.summary = %q{Useful for legacy database support, adds support for reserved word column names with ActiveRecord}
|
38
|
-
s.test_files = [
|
39
|
-
"spec/safe_attributes/safe_attributes_spec.rb",
|
40
|
-
"spec/spec_helper.rb"
|
41
|
-
]
|
42
39
|
|
43
40
|
if s.respond_to? :specification_version then
|
44
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
45
41
|
s.specification_version = 3
|
46
42
|
|
47
43
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
@@ -49,26 +45,35 @@ Gem::Specification.new do |s|
|
|
49
45
|
s.add_runtime_dependency(%q<activerecord>, ["~> 3.0.0"])
|
50
46
|
s.add_development_dependency(%q<jeweler>, [">= 1.5.2"])
|
51
47
|
s.add_development_dependency(%q<rake>, [">= 0.8.7"])
|
48
|
+
s.add_development_dependency(%q<rdoc>, [">= 0"])
|
52
49
|
s.add_development_dependency(%q<rspec>, [">= 2.3.0"])
|
53
50
|
s.add_development_dependency(%q<rcov>, [">= 0"])
|
54
51
|
s.add_development_dependency(%q<sqlite3-ruby>, [">= 0"])
|
52
|
+
s.add_development_dependency(%q<activerecord-jdbcsqlite3-adapter>, [">= 0"])
|
53
|
+
s.add_development_dependency(%q<jruby-openssl>, [">= 0"])
|
55
54
|
else
|
56
55
|
s.add_dependency(%q<activesupport>, ["~> 3.0.0"])
|
57
56
|
s.add_dependency(%q<activerecord>, ["~> 3.0.0"])
|
58
57
|
s.add_dependency(%q<jeweler>, [">= 1.5.2"])
|
59
58
|
s.add_dependency(%q<rake>, [">= 0.8.7"])
|
59
|
+
s.add_dependency(%q<rdoc>, [">= 0"])
|
60
60
|
s.add_dependency(%q<rspec>, [">= 2.3.0"])
|
61
61
|
s.add_dependency(%q<rcov>, [">= 0"])
|
62
62
|
s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
|
63
|
+
s.add_dependency(%q<activerecord-jdbcsqlite3-adapter>, [">= 0"])
|
64
|
+
s.add_dependency(%q<jruby-openssl>, [">= 0"])
|
63
65
|
end
|
64
66
|
else
|
65
67
|
s.add_dependency(%q<activesupport>, ["~> 3.0.0"])
|
66
68
|
s.add_dependency(%q<activerecord>, ["~> 3.0.0"])
|
67
69
|
s.add_dependency(%q<jeweler>, [">= 1.5.2"])
|
68
70
|
s.add_dependency(%q<rake>, [">= 0.8.7"])
|
71
|
+
s.add_dependency(%q<rdoc>, [">= 0"])
|
69
72
|
s.add_dependency(%q<rspec>, [">= 2.3.0"])
|
70
73
|
s.add_dependency(%q<rcov>, [">= 0"])
|
71
74
|
s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
|
75
|
+
s.add_dependency(%q<activerecord-jdbcsqlite3-adapter>, [">= 0"])
|
76
|
+
s.add_dependency(%q<jruby-openssl>, [">= 0"])
|
72
77
|
end
|
73
78
|
end
|
74
79
|
|
@@ -6,6 +6,10 @@ ActiveRecord::Base.connection.create_table(:my_models) do |t|
|
|
6
6
|
t.string :class
|
7
7
|
t.string :bad_attribute
|
8
8
|
t.string :good_attribute
|
9
|
+
# bad because of changed and changed? in ActiveModel
|
10
|
+
t.string :changed
|
11
|
+
# bad because normally it generates DangerousAttributeError
|
12
|
+
t.string :errors
|
9
13
|
end
|
10
14
|
|
11
15
|
class MyModel < ActiveRecord::Base
|
@@ -70,11 +74,23 @@ describe MyModel do
|
|
70
74
|
end
|
71
75
|
|
72
76
|
it "can create instance in database with special attribute name" do
|
73
|
-
m = MyModel.create(:class => 'Foo')
|
77
|
+
m = MyModel.create!(:class => 'Foo')
|
74
78
|
m = MyModel.find(m.id)
|
75
79
|
m[:class].should == 'Foo'
|
76
80
|
end
|
77
81
|
|
82
|
+
it "can create instance in database with attribute 'changed'" do
|
83
|
+
m = MyModel.create!(:class => 'Foo', :changed => 'true change')
|
84
|
+
m = MyModel.find(m.id)
|
85
|
+
m[:changed].should == 'true change'
|
86
|
+
end
|
87
|
+
|
88
|
+
it "can create instance in database with attribute 'errors'" do
|
89
|
+
m = MyModel.create!(:class => 'Foo', :errors => 'my errors')
|
90
|
+
m = MyModel.find(m.id)
|
91
|
+
m[:errors].should == 'my errors'
|
92
|
+
end
|
93
|
+
|
78
94
|
it "has class attribute" do
|
79
95
|
MyModel.new().has_attribute?('class').should be_true
|
80
96
|
end
|
@@ -97,5 +113,16 @@ describe MyModel do
|
|
97
113
|
m = MyModel.new(:class => 'Foo')
|
98
114
|
m.valid?.should be_true
|
99
115
|
end
|
116
|
+
|
117
|
+
it "changed lists attributes with unsaved changes" do
|
118
|
+
m = MyModel.new(:class => 'Foo')
|
119
|
+
m.changed.size == 1
|
120
|
+
end
|
121
|
+
|
122
|
+
it "changed? returns true if any attribute has unsaved changes" do
|
123
|
+
m = MyModel.new(:class => 'Foo')
|
124
|
+
m.changed?.should be_true
|
125
|
+
end
|
126
|
+
|
100
127
|
end
|
101
128
|
|
metadata
CHANGED
@@ -1,145 +1,142 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: safe_attributes
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 1
|
8
|
-
- 0
|
9
|
-
- 4
|
10
|
-
version: 1.0.4
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.5
|
5
|
+
prerelease:
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Brian Jones
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
date: 2011-02-04 00:00:00 -05:00
|
12
|
+
date: 2011-07-18 00:00:00.000000000 -04:00
|
19
13
|
default_executable:
|
20
|
-
dependencies:
|
21
|
-
- !ruby/object:Gem::Dependency
|
22
|
-
type: :runtime
|
23
|
-
prerelease: false
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
24
16
|
name: activesupport
|
25
|
-
|
17
|
+
requirement: &2155360580 !ruby/object:Gem::Requirement
|
26
18
|
none: false
|
27
|
-
requirements:
|
19
|
+
requirements:
|
28
20
|
- - ~>
|
29
|
-
- !ruby/object:Gem::Version
|
30
|
-
hash: 7
|
31
|
-
segments:
|
32
|
-
- 3
|
33
|
-
- 0
|
34
|
-
- 0
|
21
|
+
- !ruby/object:Gem::Version
|
35
22
|
version: 3.0.0
|
36
|
-
requirement: *id001
|
37
|
-
- !ruby/object:Gem::Dependency
|
38
23
|
type: :runtime
|
39
24
|
prerelease: false
|
25
|
+
version_requirements: *2155360580
|
26
|
+
- !ruby/object:Gem::Dependency
|
40
27
|
name: activerecord
|
41
|
-
|
28
|
+
requirement: &2155360040 !ruby/object:Gem::Requirement
|
42
29
|
none: false
|
43
|
-
requirements:
|
30
|
+
requirements:
|
44
31
|
- - ~>
|
45
|
-
- !ruby/object:Gem::Version
|
46
|
-
hash: 7
|
47
|
-
segments:
|
48
|
-
- 3
|
49
|
-
- 0
|
50
|
-
- 0
|
32
|
+
- !ruby/object:Gem::Version
|
51
33
|
version: 3.0.0
|
52
|
-
|
53
|
-
- !ruby/object:Gem::Dependency
|
54
|
-
type: :development
|
34
|
+
type: :runtime
|
55
35
|
prerelease: false
|
36
|
+
version_requirements: *2155360040
|
37
|
+
- !ruby/object:Gem::Dependency
|
56
38
|
name: jeweler
|
57
|
-
|
39
|
+
requirement: &2155359460 !ruby/object:Gem::Requirement
|
58
40
|
none: false
|
59
|
-
requirements:
|
60
|
-
- -
|
61
|
-
- !ruby/object:Gem::Version
|
62
|
-
hash: 7
|
63
|
-
segments:
|
64
|
-
- 1
|
65
|
-
- 5
|
66
|
-
- 2
|
41
|
+
requirements:
|
42
|
+
- - ! '>='
|
43
|
+
- !ruby/object:Gem::Version
|
67
44
|
version: 1.5.2
|
68
|
-
requirement: *id003
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
45
|
type: :development
|
71
46
|
prerelease: false
|
47
|
+
version_requirements: *2155359460
|
48
|
+
- !ruby/object:Gem::Dependency
|
72
49
|
name: rake
|
73
|
-
|
50
|
+
requirement: &2155358880 !ruby/object:Gem::Requirement
|
74
51
|
none: false
|
75
|
-
requirements:
|
76
|
-
- -
|
77
|
-
- !ruby/object:Gem::Version
|
78
|
-
hash: 49
|
79
|
-
segments:
|
80
|
-
- 0
|
81
|
-
- 8
|
82
|
-
- 7
|
52
|
+
requirements:
|
53
|
+
- - ! '>='
|
54
|
+
- !ruby/object:Gem::Version
|
83
55
|
version: 0.8.7
|
84
|
-
requirement: *id004
|
85
|
-
- !ruby/object:Gem::Dependency
|
86
56
|
type: :development
|
87
57
|
prerelease: false
|
58
|
+
version_requirements: *2155358880
|
59
|
+
- !ruby/object:Gem::Dependency
|
60
|
+
name: rdoc
|
61
|
+
requirement: &2155358300 !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ! '>='
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
type: :development
|
68
|
+
prerelease: false
|
69
|
+
version_requirements: *2155358300
|
70
|
+
- !ruby/object:Gem::Dependency
|
88
71
|
name: rspec
|
89
|
-
|
72
|
+
requirement: &2155357780 !ruby/object:Gem::Requirement
|
90
73
|
none: false
|
91
|
-
requirements:
|
92
|
-
- -
|
93
|
-
- !ruby/object:Gem::Version
|
94
|
-
hash: 3
|
95
|
-
segments:
|
96
|
-
- 2
|
97
|
-
- 3
|
98
|
-
- 0
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
99
77
|
version: 2.3.0
|
100
|
-
requirement: *id005
|
101
|
-
- !ruby/object:Gem::Dependency
|
102
78
|
type: :development
|
103
79
|
prerelease: false
|
80
|
+
version_requirements: *2155357780
|
81
|
+
- !ruby/object:Gem::Dependency
|
104
82
|
name: rcov
|
105
|
-
|
83
|
+
requirement: &2155351280 !ruby/object:Gem::Requirement
|
106
84
|
none: false
|
107
|
-
requirements:
|
108
|
-
- -
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
|
111
|
-
segments:
|
112
|
-
- 0
|
113
|
-
version: "0"
|
114
|
-
requirement: *id006
|
115
|
-
- !ruby/object:Gem::Dependency
|
85
|
+
requirements:
|
86
|
+
- - ! '>='
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
116
89
|
type: :development
|
117
90
|
prerelease: false
|
91
|
+
version_requirements: *2155351280
|
92
|
+
- !ruby/object:Gem::Dependency
|
118
93
|
name: sqlite3-ruby
|
119
|
-
|
94
|
+
requirement: &2155350780 !ruby/object:Gem::Requirement
|
120
95
|
none: false
|
121
|
-
requirements:
|
122
|
-
- -
|
123
|
-
- !ruby/object:Gem::Version
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
96
|
+
requirements:
|
97
|
+
- - ! '>='
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
type: :development
|
101
|
+
prerelease: false
|
102
|
+
version_requirements: *2155350780
|
103
|
+
- !ruby/object:Gem::Dependency
|
104
|
+
name: activerecord-jdbcsqlite3-adapter
|
105
|
+
requirement: &2155350220 !ruby/object:Gem::Requirement
|
106
|
+
none: false
|
107
|
+
requirements:
|
108
|
+
- - ! '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
type: :development
|
112
|
+
prerelease: false
|
113
|
+
version_requirements: *2155350220
|
114
|
+
- !ruby/object:Gem::Dependency
|
115
|
+
name: jruby-openssl
|
116
|
+
requirement: &2155349680 !ruby/object:Gem::Requirement
|
117
|
+
none: false
|
118
|
+
requirements:
|
119
|
+
- - ! '>='
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
type: :development
|
123
|
+
prerelease: false
|
124
|
+
version_requirements: *2155349680
|
125
|
+
description: Better support for legacy database schemas for ActiveRecord, such as
|
126
|
+
columns named class, or any other name that conflicts with an instance method of
|
127
|
+
ActiveRecord.
|
130
128
|
email: cbj@gnu.org
|
131
129
|
executables: []
|
132
|
-
|
133
130
|
extensions: []
|
134
|
-
|
135
|
-
extra_rdoc_files:
|
131
|
+
extra_rdoc_files:
|
136
132
|
- LICENSE
|
137
133
|
- README.rdoc
|
138
|
-
files:
|
134
|
+
files:
|
139
135
|
- .document
|
140
136
|
- .rspec
|
141
137
|
- Gemfile
|
142
138
|
- LICENSE
|
139
|
+
- NEWS.rdoc
|
143
140
|
- README.rdoc
|
144
141
|
- Rakefile
|
145
142
|
- VERSION
|
@@ -150,38 +147,32 @@ files:
|
|
150
147
|
- spec/spec_helper.rb
|
151
148
|
has_rdoc: true
|
152
149
|
homepage: http://github.com/bjones/safe_attributes
|
153
|
-
licenses:
|
150
|
+
licenses:
|
154
151
|
- MIT
|
155
152
|
post_install_message:
|
156
153
|
rdoc_options: []
|
157
|
-
|
158
|
-
require_paths:
|
154
|
+
require_paths:
|
159
155
|
- lib
|
160
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
156
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
161
157
|
none: false
|
162
|
-
requirements:
|
163
|
-
- -
|
164
|
-
- !ruby/object:Gem::Version
|
165
|
-
|
166
|
-
segments:
|
158
|
+
requirements:
|
159
|
+
- - ! '>='
|
160
|
+
- !ruby/object:Gem::Version
|
161
|
+
version: '0'
|
162
|
+
segments:
|
167
163
|
- 0
|
168
|
-
|
169
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
164
|
+
hash: -237664751269868444
|
165
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
170
166
|
none: false
|
171
|
-
requirements:
|
172
|
-
- -
|
173
|
-
- !ruby/object:Gem::Version
|
174
|
-
|
175
|
-
segments:
|
176
|
-
- 0
|
177
|
-
version: "0"
|
167
|
+
requirements:
|
168
|
+
- - ! '>='
|
169
|
+
- !ruby/object:Gem::Version
|
170
|
+
version: '0'
|
178
171
|
requirements: []
|
179
|
-
|
180
172
|
rubyforge_project:
|
181
|
-
rubygems_version: 1.
|
173
|
+
rubygems_version: 1.6.2
|
182
174
|
signing_key:
|
183
175
|
specification_version: 3
|
184
|
-
summary: Useful for legacy database support, adds support for reserved word column
|
185
|
-
|
186
|
-
|
187
|
-
- spec/spec_helper.rb
|
176
|
+
summary: Useful for legacy database support, adds support for reserved word column
|
177
|
+
names with ActiveRecord
|
178
|
+
test_files: []
|