hot_like_sauce 0.1.0
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/.document +5 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +50 -0
- data/LICENSE.txt +20 -0
- data/README.md +65 -0
- data/Rakefile +44 -0
- data/VERSION +1 -0
- data/hot_like_sauce.gemspec +67 -0
- data/lib/hot_like_sauce.rb +120 -0
- data/spec/.DS_Store +0 -0
- data/spec/hot_like_sauce_spec.rb +129 -0
- data/spec/spec_helper.rb +15 -0
- data/spec/support/schema.rb +17 -0
- metadata +129 -0
data/.document
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
|
4
|
+
gem "activerecord", ">= 3.2.0"
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
group :development do
|
9
|
+
gem "rspec", "~> 2.8.0"
|
10
|
+
gem "rdoc", "~> 3.12"
|
11
|
+
gem "bundler", "~> 1.0.0"
|
12
|
+
gem "jeweler", "~> 1.8.3"
|
13
|
+
gem "sqlite3", "~> 1.3.5"
|
14
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
activemodel (3.2.3)
|
5
|
+
activesupport (= 3.2.3)
|
6
|
+
builder (~> 3.0.0)
|
7
|
+
activerecord (3.2.3)
|
8
|
+
activemodel (= 3.2.3)
|
9
|
+
activesupport (= 3.2.3)
|
10
|
+
arel (~> 3.0.2)
|
11
|
+
tzinfo (~> 0.3.29)
|
12
|
+
activesupport (3.2.3)
|
13
|
+
i18n (~> 0.6)
|
14
|
+
multi_json (~> 1.0)
|
15
|
+
arel (3.0.2)
|
16
|
+
builder (3.0.0)
|
17
|
+
diff-lcs (1.1.3)
|
18
|
+
git (1.2.5)
|
19
|
+
i18n (0.6.0)
|
20
|
+
jeweler (1.8.3)
|
21
|
+
bundler (~> 1.0)
|
22
|
+
git (>= 1.2.5)
|
23
|
+
rake
|
24
|
+
rdoc
|
25
|
+
json (1.7.0)
|
26
|
+
multi_json (1.3.4)
|
27
|
+
rake (0.9.2.2)
|
28
|
+
rdoc (3.12)
|
29
|
+
json (~> 1.4)
|
30
|
+
rspec (2.8.0)
|
31
|
+
rspec-core (~> 2.8.0)
|
32
|
+
rspec-expectations (~> 2.8.0)
|
33
|
+
rspec-mocks (~> 2.8.0)
|
34
|
+
rspec-core (2.8.0)
|
35
|
+
rspec-expectations (2.8.0)
|
36
|
+
diff-lcs (~> 1.1.2)
|
37
|
+
rspec-mocks (2.8.0)
|
38
|
+
sqlite3 (1.3.5)
|
39
|
+
tzinfo (0.3.33)
|
40
|
+
|
41
|
+
PLATFORMS
|
42
|
+
ruby
|
43
|
+
|
44
|
+
DEPENDENCIES
|
45
|
+
activerecord (>= 3.2.0)
|
46
|
+
bundler (~> 1.0.0)
|
47
|
+
jeweler (~> 1.8.3)
|
48
|
+
rdoc (~> 3.12)
|
49
|
+
rspec (~> 2.8.0)
|
50
|
+
sqlite3 (~> 1.3.5)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Justin Derrek Van Eaton
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
# hot-like-sauce
|
2
|
+
|
3
|
+
This is some sweet code for ActiveRecord (rails) that will allow you to obscure database fields. The data will always be obscured in the database, but can be read as plaintext or obscured. This is useful for admin views where you can display obscured data for people who shouldn't be seeing it.
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
gem 'hot_like_sauce'
|
9
|
+
```
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
class Post < ActiveRecord::Base
|
13
|
+
attr_obscurable :body
|
14
|
+
end
|
15
|
+
```
|
16
|
+
|
17
|
+
By default, when you read the value you get the original plain text.
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
p = Post.create(:body => "readable text")
|
21
|
+
p.body
|
22
|
+
#=> "readable text"
|
23
|
+
|
24
|
+
Post.obscure_read_on_fields!(:body)
|
25
|
+
p.body
|
26
|
+
#=> "էu??+]?S???^Vx????gzq?'?"
|
27
|
+
```
|
28
|
+
|
29
|
+
You can configure this on a per field basis by default
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
class Post < ActiveRecord::Base
|
33
|
+
attr_obscurable :body, :obscure_on_read => true
|
34
|
+
end
|
35
|
+
|
36
|
+
p = Post.create(:body => "readable text")
|
37
|
+
p.body
|
38
|
+
#=> "էu??+]?S???^Vx????gzq?'?"
|
39
|
+
```
|
40
|
+
|
41
|
+
`Post.obscure_read_on_fields!` can be called with no arguments to set all attr_obscurable fields. The inverse method is `Post.unobscure_read_on_fields!`
|
42
|
+
|
43
|
+
## Configuration
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
HotLikeSauce.secret_key = "this-should-be-long-and-random"
|
47
|
+
|
48
|
+
HotLikeSauce.crypto_method = "aes-256-cbc" # default's to aes-256-cbc
|
49
|
+
```
|
50
|
+
|
51
|
+
## Contributing to hot-like-sauce
|
52
|
+
|
53
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
54
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
55
|
+
* Fork the project.
|
56
|
+
* Start a feature/bugfix branch.
|
57
|
+
* Commit and push until you are happy with your contribution.
|
58
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
59
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
60
|
+
|
61
|
+
## Copyright
|
62
|
+
|
63
|
+
Copyright (c) 2012 Justin Derrek Van Eaton. See LICENSE.txt for
|
64
|
+
further details.
|
65
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "hot_like_sauce"
|
18
|
+
gem.homepage = "http://github.com/jstin/hot_like_sauce"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{Rails gem for obscuring database fields}
|
21
|
+
gem.description = %Q{Rails gem for obscuring database fields. Uses OpenSSL.}
|
22
|
+
gem.email = "jvaneaton@tangogroup.com"
|
23
|
+
gem.authors = ["Justin Derrek Van Eaton"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rspec/core'
|
29
|
+
require 'rspec/core/rake_task'
|
30
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
31
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
32
|
+
end
|
33
|
+
|
34
|
+
task :default => :spec
|
35
|
+
|
36
|
+
require 'rdoc/task'
|
37
|
+
Rake::RDocTask.new do |rdoc|
|
38
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
39
|
+
|
40
|
+
rdoc.rdoc_dir = 'rdoc'
|
41
|
+
rdoc.title = "hot_like_sauce #{version}"
|
42
|
+
rdoc.rdoc_files.include('README*')
|
43
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
44
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "hot_like_sauce"
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Justin Derrek Van Eaton"]
|
12
|
+
s.date = "2012-05-03"
|
13
|
+
s.description = "Rails gem for obscuring database fields. Uses OpenSSL."
|
14
|
+
s.email = "jvaneaton@tangogroup.com"
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.md"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
"Gemfile",
|
22
|
+
"Gemfile.lock",
|
23
|
+
"LICENSE.txt",
|
24
|
+
"README.md",
|
25
|
+
"Rakefile",
|
26
|
+
"VERSION",
|
27
|
+
"hot_like_sauce.gemspec",
|
28
|
+
"lib/hot_like_sauce.rb",
|
29
|
+
"spec/.DS_Store",
|
30
|
+
"spec/hot_like_sauce_spec.rb",
|
31
|
+
"spec/spec_helper.rb",
|
32
|
+
"spec/support/schema.rb"
|
33
|
+
]
|
34
|
+
s.homepage = "http://github.com/jstin/hot_like_sauce"
|
35
|
+
s.licenses = ["MIT"]
|
36
|
+
s.require_paths = ["lib"]
|
37
|
+
s.rubygems_version = "1.8.15"
|
38
|
+
s.summary = "Rails gem for obscuring database fields"
|
39
|
+
|
40
|
+
if s.respond_to? :specification_version then
|
41
|
+
s.specification_version = 3
|
42
|
+
|
43
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
44
|
+
s.add_runtime_dependency(%q<activerecord>, [">= 3.2.0"])
|
45
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
|
46
|
+
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
47
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
48
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.8.3"])
|
49
|
+
s.add_development_dependency(%q<sqlite3>, ["~> 1.3.5"])
|
50
|
+
else
|
51
|
+
s.add_dependency(%q<activerecord>, [">= 3.2.0"])
|
52
|
+
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
53
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
54
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
55
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
|
56
|
+
s.add_dependency(%q<sqlite3>, ["~> 1.3.5"])
|
57
|
+
end
|
58
|
+
else
|
59
|
+
s.add_dependency(%q<activerecord>, [">= 3.2.0"])
|
60
|
+
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
61
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
62
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
63
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
|
64
|
+
s.add_dependency(%q<sqlite3>, ["~> 1.3.5"])
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
@@ -0,0 +1,120 @@
|
|
1
|
+
require 'openssl'
|
2
|
+
require 'active_record'
|
3
|
+
|
4
|
+
module HotLikeSauce
|
5
|
+
|
6
|
+
def self.secret_key
|
7
|
+
@secret_key ||= "please_init_this_somewhere_before_using"
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.secret_key=(val)
|
11
|
+
@secret_key = val
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.crypto_method
|
15
|
+
@crypto_method ||= "aes-256-cbc"
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.crypto_method=(val)
|
19
|
+
@crypto_method = val
|
20
|
+
end
|
21
|
+
|
22
|
+
module ARMethods
|
23
|
+
|
24
|
+
def inherited(child_class)
|
25
|
+
child_class.send :extend, HotLikeSauce::ClassMethods
|
26
|
+
child_class.send :include, HotLikeSauce::InstanceMethods
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
module ClassMethods
|
32
|
+
|
33
|
+
def obscured_fields
|
34
|
+
@obscured_fields ||= []
|
35
|
+
end
|
36
|
+
|
37
|
+
def obscured_fields=(val)
|
38
|
+
@obscured_fields = val
|
39
|
+
end
|
40
|
+
|
41
|
+
def unobscured_read_fields
|
42
|
+
@unobscured_read_fields ||= []
|
43
|
+
end
|
44
|
+
|
45
|
+
def unobscured_read_fields=(val)
|
46
|
+
@unobscured_read_fields = val
|
47
|
+
end
|
48
|
+
|
49
|
+
def attr_obscurable(*args)
|
50
|
+
fields = args.map {|arg| arg if arg.is_a?(Symbol)}.compact
|
51
|
+
options = args.map {|arg| arg if arg.is_a?(Hash)}.compact.first
|
52
|
+
options ||= {}
|
53
|
+
|
54
|
+
fields.each do |field|
|
55
|
+
|
56
|
+
type = self.columns_hash[field.to_s].type
|
57
|
+
raise "#{field} must be a string or text field" unless type == :string || type == :text
|
58
|
+
self.obscured_fields = (self.obscured_fields << field).uniq
|
59
|
+
self.unobscured_read_fields = (self.unobscured_read_fields << field).uniq unless options[:obscure_on_read] == true
|
60
|
+
|
61
|
+
define_method field do
|
62
|
+
super()
|
63
|
+
value = read_attribute(field)
|
64
|
+
self.class.unobscured_read_fields.include?(field) ? _unobscure(value) : value
|
65
|
+
end
|
66
|
+
|
67
|
+
define_method "#{field}=" do |value|
|
68
|
+
super(value)
|
69
|
+
write_attribute(field, _obscure(value))
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
def obscure_read_on_fields!(*fields_array)
|
77
|
+
if fields_array.empty?
|
78
|
+
self.unobscured_read_fields = []
|
79
|
+
else
|
80
|
+
self.unobscured_read_fields -= fields_array
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def unobscure_read_on_fields!(*fields_array)
|
85
|
+
if fields_array.empty?
|
86
|
+
self.unobscured_read_fields = self.obscured_fields
|
87
|
+
else
|
88
|
+
self.unobscured_read_fields += self.obscured_fields & fields_array
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
|
+
module InstanceMethods
|
95
|
+
|
96
|
+
private
|
97
|
+
|
98
|
+
def _obscure(value)
|
99
|
+
_crypt :encrypt, HotLikeSauce::secret_key, value
|
100
|
+
end
|
101
|
+
|
102
|
+
def _unobscure(value)
|
103
|
+
_crypt :decrypt, HotLikeSauce::secret_key, value
|
104
|
+
end
|
105
|
+
|
106
|
+
def _crypt(method, key, value)
|
107
|
+
cipher = OpenSSL::Cipher::Cipher.new(HotLikeSauce::crypto_method)
|
108
|
+
cipher.send(method)
|
109
|
+
cipher.pkcs5_keyivgen(key)
|
110
|
+
result = cipher.update(value)
|
111
|
+
result << cipher.final
|
112
|
+
result.force_encoding('UTF-8')
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
116
|
+
|
117
|
+
end
|
118
|
+
|
119
|
+
|
120
|
+
ActiveRecord::Base.send :extend, HotLikeSauce::ARMethods
|
data/spec/.DS_Store
ADDED
Binary file
|
@@ -0,0 +1,129 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "HotLikeSauce" do
|
4
|
+
|
5
|
+
describe "obscures text and strings" do
|
6
|
+
|
7
|
+
before :each do
|
8
|
+
Object.send(:remove_const, :Post) if defined?(Post)
|
9
|
+
Object.send(:remove_const, :Grape) if defined?(Grape)
|
10
|
+
class Post < ActiveRecord::Base
|
11
|
+
attr_obscurable :title
|
12
|
+
end
|
13
|
+
|
14
|
+
class Grape < ActiveRecord::Base
|
15
|
+
attr_obscurable :title, :contents
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
it "can obscure fields to the datatbase" do
|
20
|
+
p = Post.new
|
21
|
+
p.title = "raison brain"
|
22
|
+
p.save
|
23
|
+
p.reload
|
24
|
+
p.title.should == "raison brain"
|
25
|
+
|
26
|
+
Object.send(:remove_const, :Post)
|
27
|
+
class Post < ActiveRecord::Base
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
p = Post.find p.id
|
32
|
+
p.title.should_not == "raison brain"
|
33
|
+
end
|
34
|
+
|
35
|
+
it "can only obscure the fields specified" do
|
36
|
+
p = Post.new
|
37
|
+
p.body = "water is tasty and wonderful"
|
38
|
+
p.save
|
39
|
+
|
40
|
+
Object.send(:remove_const, :Post)
|
41
|
+
class Post < ActiveRecord::Base
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
p = Post.find p.id
|
46
|
+
p.body.should == "water is tasty and wonderful"
|
47
|
+
end
|
48
|
+
|
49
|
+
it "can obscure fields on read" do
|
50
|
+
p = Post.new
|
51
|
+
p.title = "we all belong"
|
52
|
+
p.save
|
53
|
+
p.reload
|
54
|
+
|
55
|
+
Post.obscure_read_on_fields!
|
56
|
+
p.title.should_not == "we all belong"
|
57
|
+
|
58
|
+
Post.unobscure_read_on_fields!
|
59
|
+
|
60
|
+
p.title.should == "we all belong"
|
61
|
+
end
|
62
|
+
|
63
|
+
it "can obscure fields on read by default" do
|
64
|
+
Object.send(:remove_const, :Post)
|
65
|
+
class Post < ActiveRecord::Base
|
66
|
+
attr_obscurable :title, :obscure_on_read => true
|
67
|
+
end
|
68
|
+
|
69
|
+
p = Post.new
|
70
|
+
p.title = "we all belong"
|
71
|
+
p.save
|
72
|
+
p.reload
|
73
|
+
|
74
|
+
p.title.should_not == "we all belong"
|
75
|
+
end
|
76
|
+
|
77
|
+
it "can obscure individual fields on read" do
|
78
|
+
p = Grape.new
|
79
|
+
p.title = "i'm the doctor dawg"
|
80
|
+
p.contents = "who are you to be yourself?"
|
81
|
+
p.save
|
82
|
+
p.reload
|
83
|
+
|
84
|
+
Post.obscure_read_on_fields!(:contents)
|
85
|
+
p.title.should == "i'm the doctor dawg"
|
86
|
+
p.reload
|
87
|
+
p.contents.should == "who are you to be yourself?"
|
88
|
+
|
89
|
+
Grape.obscure_read_on_fields!(:contents)
|
90
|
+
p.title.should == "i'm the doctor dawg"
|
91
|
+
p.contents.should_not == "who are you to be yourself?"
|
92
|
+
|
93
|
+
Grape.unobscure_read_on_fields!(:contents)
|
94
|
+
p.title.should == "i'm the doctor dawg"
|
95
|
+
p.contents.should == "who are you to be yourself?"
|
96
|
+
end
|
97
|
+
|
98
|
+
it "can obscure special charaters" do
|
99
|
+
g = Grape.create(:contents => "!@$%^&*()\n")
|
100
|
+
g.contents.should == "!@$%^&*()\n"
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
104
|
+
|
105
|
+
describe "validates proper fields" do
|
106
|
+
|
107
|
+
before :each do
|
108
|
+
Object.send(:remove_const, :Post) if defined?(Post)
|
109
|
+
Object.send(:remove_const, :Grape) if defined?(Grape)
|
110
|
+
class Post < ActiveRecord::Base
|
111
|
+
attr_obscurable :title
|
112
|
+
end
|
113
|
+
|
114
|
+
class Grape < ActiveRecord::Base
|
115
|
+
attr_obscurable :title
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
it "can not obscure integer fields" do
|
120
|
+
expect { Grape.attr_obscurable(:vineyard_id) }.should raise_exception
|
121
|
+
end
|
122
|
+
|
123
|
+
it "can not obscure datetime fields" do
|
124
|
+
expect { Grape.attr_obscurable(:created_at) }.should raise_exception
|
125
|
+
end
|
126
|
+
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'hot_like_sauce'
|
5
|
+
|
6
|
+
|
7
|
+
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => File.dirname(__FILE__) + "/test.sqlite")
|
8
|
+
|
9
|
+
# Requires supporting files with custom matchers and macros, etc,
|
10
|
+
# in ./support/ and its subdirectories.
|
11
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
12
|
+
|
13
|
+
RSpec.configure do |config|
|
14
|
+
|
15
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
ActiveRecord::Schema.define do
|
2
|
+
self.verbose = false
|
3
|
+
|
4
|
+
create_table :posts, :force => true do |t|
|
5
|
+
t.string :title
|
6
|
+
t.text :body
|
7
|
+
t.timestamps
|
8
|
+
end
|
9
|
+
|
10
|
+
create_table :grapes, :force => true do |t|
|
11
|
+
t.integer :vineyard_id
|
12
|
+
t.string :title
|
13
|
+
t.text :contents
|
14
|
+
t.timestamps
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hot_like_sauce
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Justin Derrek Van Eaton
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-05-03 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: activerecord
|
16
|
+
requirement: &70259113489420 !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: *70259113489420
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rspec
|
27
|
+
requirement: &70259115530380 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 2.8.0
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70259115530380
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rdoc
|
38
|
+
requirement: &70259115529400 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '3.12'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70259115529400
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: bundler
|
49
|
+
requirement: &70259115528620 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.0.0
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *70259115528620
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: jeweler
|
60
|
+
requirement: &70259115526160 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ~>
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: 1.8.3
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *70259115526160
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: sqlite3
|
71
|
+
requirement: &70259115524400 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ~>
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: 1.3.5
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *70259115524400
|
80
|
+
description: Rails gem for obscuring database fields. Uses OpenSSL.
|
81
|
+
email: jvaneaton@tangogroup.com
|
82
|
+
executables: []
|
83
|
+
extensions: []
|
84
|
+
extra_rdoc_files:
|
85
|
+
- LICENSE.txt
|
86
|
+
- README.md
|
87
|
+
files:
|
88
|
+
- .document
|
89
|
+
- Gemfile
|
90
|
+
- Gemfile.lock
|
91
|
+
- LICENSE.txt
|
92
|
+
- README.md
|
93
|
+
- Rakefile
|
94
|
+
- VERSION
|
95
|
+
- hot_like_sauce.gemspec
|
96
|
+
- lib/hot_like_sauce.rb
|
97
|
+
- spec/.DS_Store
|
98
|
+
- spec/hot_like_sauce_spec.rb
|
99
|
+
- spec/spec_helper.rb
|
100
|
+
- spec/support/schema.rb
|
101
|
+
homepage: http://github.com/jstin/hot_like_sauce
|
102
|
+
licenses:
|
103
|
+
- MIT
|
104
|
+
post_install_message:
|
105
|
+
rdoc_options: []
|
106
|
+
require_paths:
|
107
|
+
- lib
|
108
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
109
|
+
none: false
|
110
|
+
requirements:
|
111
|
+
- - ! '>='
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
segments:
|
115
|
+
- 0
|
116
|
+
hash: -2965139016655371852
|
117
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
+
none: false
|
119
|
+
requirements:
|
120
|
+
- - ! '>='
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
requirements: []
|
124
|
+
rubyforge_project:
|
125
|
+
rubygems_version: 1.8.15
|
126
|
+
signing_key:
|
127
|
+
specification_version: 3
|
128
|
+
summary: Rails gem for obscuring database fields
|
129
|
+
test_files: []
|