obscured_id 0.1.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.
Files changed (59) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +109 -0
  4. data/Rakefile +38 -0
  5. data/lib/generators/obscured_id/initializer_generator.rb +10 -0
  6. data/lib/generators/obscured_id/migration_generator.rb +22 -0
  7. data/lib/obscured_id/obscured_id.rb +63 -0
  8. data/lib/obscured_id/railtie.rb +26 -0
  9. data/lib/obscured_id/version.rb +3 -0
  10. data/lib/obscured_id.rb +5 -0
  11. data/lib/tasks/obscured_id.rake +18 -0
  12. data/spec/Gemfile +17 -0
  13. data/spec/Gemfile.lock +111 -0
  14. data/spec/MIT-LICENSE +20 -0
  15. data/spec/README.md +2 -0
  16. data/spec/README.rdoc +3 -0
  17. data/spec/Rakefile +38 -0
  18. data/spec/dummy/README.rdoc +261 -0
  19. data/spec/dummy/Rakefile +7 -0
  20. data/spec/dummy/app/assets/javascripts/application.js +15 -0
  21. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  22. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  23. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  24. data/spec/dummy/app/models/thing_with_configured_obscured_id.rb +3 -0
  25. data/spec/dummy/app/models/thing_with_obscured_id.rb +3 -0
  26. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  27. data/spec/dummy/config/application.rb +59 -0
  28. data/spec/dummy/config/boot.rb +10 -0
  29. data/spec/dummy/config/database.yml +25 -0
  30. data/spec/dummy/config/environment.rb +5 -0
  31. data/spec/dummy/config/environments/development.rb +37 -0
  32. data/spec/dummy/config/environments/production.rb +67 -0
  33. data/spec/dummy/config/environments/test.rb +37 -0
  34. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  35. data/spec/dummy/config/initializers/inflections.rb +15 -0
  36. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  37. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  38. data/spec/dummy/config/initializers/session_store.rb +8 -0
  39. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  40. data/spec/dummy/config/locales/en.yml +5 -0
  41. data/spec/dummy/config/routes.rb +58 -0
  42. data/spec/dummy/config.ru +4 -0
  43. data/spec/dummy/db/development.sqlite3 +0 -0
  44. data/spec/dummy/db/migrate/20130507231624_create_thing_with_obscured_ids.rb +10 -0
  45. data/spec/dummy/db/migrate/20130507235114_create_thing_with_configured_obscured_ids.rb +8 -0
  46. data/spec/dummy/db/schema.rb +28 -0
  47. data/spec/dummy/db/test.sqlite3 +0 -0
  48. data/spec/dummy/log/development.log +270 -0
  49. data/spec/dummy/log/test.log +2279 -0
  50. data/spec/dummy/public/404.html +26 -0
  51. data/spec/dummy/public/422.html +26 -0
  52. data/spec/dummy/public/500.html +25 -0
  53. data/spec/dummy/public/favicon.ico +0 -0
  54. data/spec/dummy/script/rails +6 -0
  55. data/spec/models/thing_with_configured_obscured_id_spec.rb +31 -0
  56. data/spec/models/thing_with_obscured_id_spec.rb +72 -0
  57. data/spec/obscured_id.gemspec +23 -0
  58. data/spec/spec_helper.rb +38 -0
  59. metadata +180 -0
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/404.html -->
21
+ <div class="dialog">
22
+ <h1>The page you were looking for doesn't exist.</h1>
23
+ <p>You may have mistyped the address or the page may have moved.</p>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/422.html -->
21
+ <div class="dialog">
22
+ <h1>The change you wanted was rejected.</h1>
23
+ <p>Maybe you tried to change something you didn't have access to.</p>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,25 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/500.html -->
21
+ <div class="dialog">
22
+ <h1>We're sorry, but something went wrong.</h1>
23
+ </div>
24
+ </body>
25
+ </html>
File without changes
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
+
4
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
5
+ require File.expand_path('../../config/boot', __FILE__)
6
+ require 'rails/commands'
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ describe ThingWithConfiguredObscuredId do
4
+ before(:all) do
5
+ @field = ThingWithConfiguredObscuredId.obscured_id_field
6
+ @secret_token = ThingWithConfiguredObscuredId.obscured_id_secret_token
7
+ end
8
+
9
+ before(:each) do
10
+ @configured_thing = ThingWithConfiguredObscuredId.create
11
+ end
12
+
13
+ it "should not automatically assign an obscured id after save" do
14
+ @configured_thing[@field].to_s.should be_empty
15
+ end
16
+
17
+ it "should assign an obscured id to the specifed column" do
18
+ @configured_thing.set_obscured_id
19
+ @configured_thing[@field].to_s.should_not be_empty
20
+ end
21
+
22
+ it "should assign an obscured id with the specified secret token" do
23
+ @configured_thing.set_obscured_id
24
+ @configured_thing[@field].should == OpenSSL::HMAC.hexdigest(OpenSSL::Digest.const_get(:SHA1).new, @secret_token, "#{@configured_thing.id}#{@configured_thing.created_at.to_i}")
25
+ end
26
+
27
+ it "should not share settings with another subclass" do
28
+ ThingWithObscuredId.obscured_id_field.should_not == @field
29
+ ThingWithObscuredId.obscured_id_secret_token.should_not == @secret_token
30
+ end
31
+ end
@@ -0,0 +1,72 @@
1
+ require 'spec_helper'
2
+
3
+ describe ThingWithObscuredId do
4
+ after(:all) do
5
+ ThingWithObscuredId.destroy_all
6
+ end
7
+
8
+ describe "default intialization" do
9
+
10
+ it "should assign an obscured id to the obscured_id column after save" do
11
+ thing = ThingWithObscuredId.create
12
+ thing.obscured_id.to_s.should_not be_empty
13
+ end
14
+
15
+ it "should assign an obscured id with an empty salt" do
16
+ thing = ThingWithObscuredId.create
17
+ thing.obscured_id.should == OpenSSL::HMAC.hexdigest(OpenSSL::Digest.const_get(:SHA1).new, nil.to_s, "#{thing.id}#{thing.created_at.to_i}")
18
+ end
19
+
20
+ it "should respect record obscured id setting" do
21
+ ActiveRecord::Base.record_obscured_ids = false
22
+ ThingWithObscuredId.create.obscured_id.should be_nil
23
+ ActiveRecord::Base.record_obscured_ids = true
24
+ ThingWithObscuredId.create.obscured_id.should_not be_nil
25
+ end
26
+
27
+ describe :set_obscured_ids do
28
+ it "should update all records with an obscured id" do
29
+ ActiveRecord::Base.record_obscured_ids = false
30
+ 5.times.each do
31
+ ThingWithObscuredId.create
32
+ end
33
+
34
+ ThingWithObscuredId.set_obscured_ids
35
+
36
+ # Make sure all the things were created
37
+ ThingWithObscuredId.count.should == 5
38
+
39
+ # Make sure all the things have the correct obscured id
40
+ ThingWithObscuredId.all do |thing|
41
+ thing.obscured_id.should == OpenSSL::HMAC.hexdigest(OpenSSL::Digest.const_get(:SHA1).new, nil.to_s, "#{thing.id}#{thing.created_at.to_i}")
42
+ end
43
+ end
44
+ end
45
+
46
+ end # default intialization
47
+
48
+ describe "rails intialization" do
49
+ before(:all) do
50
+ @secret_token = SecureRandom.hex
51
+ @field = :other_id
52
+ Dummy::Application.config.obscured_id_secret_token = @secret_token
53
+ Dummy::Application.config.obscured_id_field = @field
54
+
55
+ Object.send(:remove_const, 'ThingWithObscuredId')
56
+ ObscuredId::Railtie.set_defaults_from_configuration
57
+ load 'thing_with_obscured_id.rb'
58
+
59
+ @thing = ThingWithObscuredId.create
60
+ end
61
+
62
+ it "should assign an obscured id to the specifed column" do
63
+ @thing[@field].to_s.should_not be_empty
64
+ end
65
+
66
+ it "should assign an obscured id with the specified salt" do
67
+ @thing[@field].should == OpenSSL::HMAC.hexdigest(OpenSSL::Digest.const_get(:SHA1).new, @secret_token, "#{@thing.id}#{@thing.created_at.to_i}")
68
+ end
69
+
70
+ end # rails intialization
71
+
72
+ end # ThingWithObscuredId
@@ -0,0 +1,23 @@
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+
3
+ # Maintain your gem's version:
4
+ require "obscured_id/version"
5
+
6
+ # Describe your gem and declare its dependencies:
7
+ Gem::Specification.new do |s|
8
+ s.name = "obscured_id"
9
+ s.version = ObscuredId::VERSION
10
+ s.authors = ["TODO: Your name"]
11
+ s.email = ["TODO: Your email"]
12
+ s.homepage = "TODO"
13
+ s.summary = "TODO: Summary of ObscuredId."
14
+ s.description = "TODO: Description of ObscuredId."
15
+
16
+ s.files = Dir["{app,config,db,lib}/**/*"] + ["MIT-LICENSE", "Rakefile", "README.rdoc"]
17
+ s.test_files = Dir["test/**/*"]
18
+
19
+ s.add_dependency "rails", "~> 3.2.13"
20
+
21
+ s.add_development_dependency "sqlite3"
22
+ s.add_development_dependency "rspec-rails"
23
+ end
@@ -0,0 +1,38 @@
1
+ # This file is copied to spec/ when you run 'rails generate rspec:install'
2
+ ENV["RAILS_ENV"] ||= 'test'
3
+ require File.expand_path("../dummy/config/environment", __FILE__)
4
+ require 'rspec/rails'
5
+ require 'rspec/autorun'
6
+
7
+ # Requires supporting ruby files with custom matchers and macros, etc,
8
+ # in spec/support/ and its subdirectories.
9
+ Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
10
+
11
+ RSpec.configure do |config|
12
+ # ## Mock Framework
13
+ #
14
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
15
+ #
16
+ # config.mock_with :mocha
17
+ # config.mock_with :flexmock
18
+ # config.mock_with :rr
19
+
20
+ # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
21
+ config.fixture_path = "#{::Rails.root}/spec/fixtures"
22
+
23
+ # If you're not using ActiveRecord, or you'd prefer not to run each of your
24
+ # examples within a transaction, remove the following line or assign false
25
+ # instead of true.
26
+ config.use_transactional_fixtures = true
27
+
28
+ # If true, the base class of anonymous controllers will be inferred
29
+ # automatically. This will be the default behavior in future versions of
30
+ # rspec-rails.
31
+ config.infer_base_class_for_anonymous_controllers = false
32
+
33
+ # Run specs in random order to surface order dependencies. If you find an
34
+ # order dependency and want to debug it, you can fix the order by providing
35
+ # the seed, which is printed after each run.
36
+ # --seed 1234
37
+ config.order = "random"
38
+ end
metadata ADDED
@@ -0,0 +1,180 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: obscured_id
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - halff
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2013-05-09 00:00:00 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ prerelease: false
17
+ requirement: &id001 !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 3.2.13
22
+ type: :runtime
23
+ version_requirements: *id001
24
+ - !ruby/object:Gem::Dependency
25
+ name: sqlite3
26
+ prerelease: false
27
+ requirement: &id002 !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - &id003
30
+ - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: "0"
33
+ type: :development
34
+ version_requirements: *id002
35
+ - !ruby/object:Gem::Dependency
36
+ name: rspec-rails
37
+ prerelease: false
38
+ requirement: &id004 !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - *id003
41
+ type: :development
42
+ version_requirements: *id004
43
+ description: Add an obscured id columns to any Rails model.
44
+ email:
45
+ - email@larrhalff.com
46
+ executables: []
47
+
48
+ extensions: []
49
+
50
+ extra_rdoc_files: []
51
+
52
+ files:
53
+ - lib/generators/obscured_id/initializer_generator.rb
54
+ - lib/generators/obscured_id/migration_generator.rb
55
+ - lib/obscured_id/obscured_id.rb
56
+ - lib/obscured_id/railtie.rb
57
+ - lib/obscured_id/version.rb
58
+ - lib/obscured_id.rb
59
+ - lib/tasks/obscured_id.rake
60
+ - MIT-LICENSE
61
+ - Rakefile
62
+ - README.md
63
+ - spec/dummy/app/assets/javascripts/application.js
64
+ - spec/dummy/app/assets/stylesheets/application.css
65
+ - spec/dummy/app/controllers/application_controller.rb
66
+ - spec/dummy/app/helpers/application_helper.rb
67
+ - spec/dummy/app/models/thing_with_configured_obscured_id.rb
68
+ - spec/dummy/app/models/thing_with_obscured_id.rb
69
+ - spec/dummy/app/views/layouts/application.html.erb
70
+ - spec/dummy/config/application.rb
71
+ - spec/dummy/config/boot.rb
72
+ - spec/dummy/config/database.yml
73
+ - spec/dummy/config/environment.rb
74
+ - spec/dummy/config/environments/development.rb
75
+ - spec/dummy/config/environments/production.rb
76
+ - spec/dummy/config/environments/test.rb
77
+ - spec/dummy/config/initializers/backtrace_silencers.rb
78
+ - spec/dummy/config/initializers/inflections.rb
79
+ - spec/dummy/config/initializers/mime_types.rb
80
+ - spec/dummy/config/initializers/secret_token.rb
81
+ - spec/dummy/config/initializers/session_store.rb
82
+ - spec/dummy/config/initializers/wrap_parameters.rb
83
+ - spec/dummy/config/locales/en.yml
84
+ - spec/dummy/config/routes.rb
85
+ - spec/dummy/config.ru
86
+ - spec/dummy/db/development.sqlite3
87
+ - spec/dummy/db/migrate/20130507231624_create_thing_with_obscured_ids.rb
88
+ - spec/dummy/db/migrate/20130507235114_create_thing_with_configured_obscured_ids.rb
89
+ - spec/dummy/db/schema.rb
90
+ - spec/dummy/db/test.sqlite3
91
+ - spec/dummy/log/development.log
92
+ - spec/dummy/log/test.log
93
+ - spec/dummy/public/404.html
94
+ - spec/dummy/public/422.html
95
+ - spec/dummy/public/500.html
96
+ - spec/dummy/public/favicon.ico
97
+ - spec/dummy/Rakefile
98
+ - spec/dummy/README.rdoc
99
+ - spec/dummy/script/rails
100
+ - spec/Gemfile
101
+ - spec/Gemfile.lock
102
+ - spec/MIT-LICENSE
103
+ - spec/models/thing_with_configured_obscured_id_spec.rb
104
+ - spec/models/thing_with_obscured_id_spec.rb
105
+ - spec/obscured_id.gemspec
106
+ - spec/Rakefile
107
+ - spec/README.md
108
+ - spec/README.rdoc
109
+ - spec/spec_helper.rb
110
+ homepage: https://github.com/lhalff/obscured_id
111
+ licenses: []
112
+
113
+ metadata: {}
114
+
115
+ post_install_message:
116
+ rdoc_options: []
117
+
118
+ require_paths:
119
+ - lib
120
+ required_ruby_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - *id003
123
+ required_rubygems_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - *id003
126
+ requirements: []
127
+
128
+ rubyforge_project:
129
+ rubygems_version: 2.0.3
130
+ signing_key:
131
+ specification_version: 4
132
+ summary: Add an obscured id columns to any Rails model.
133
+ test_files:
134
+ - spec/dummy/app/assets/javascripts/application.js
135
+ - spec/dummy/app/assets/stylesheets/application.css
136
+ - spec/dummy/app/controllers/application_controller.rb
137
+ - spec/dummy/app/helpers/application_helper.rb
138
+ - spec/dummy/app/models/thing_with_configured_obscured_id.rb
139
+ - spec/dummy/app/models/thing_with_obscured_id.rb
140
+ - spec/dummy/app/views/layouts/application.html.erb
141
+ - spec/dummy/config/application.rb
142
+ - spec/dummy/config/boot.rb
143
+ - spec/dummy/config/database.yml
144
+ - spec/dummy/config/environment.rb
145
+ - spec/dummy/config/environments/development.rb
146
+ - spec/dummy/config/environments/production.rb
147
+ - spec/dummy/config/environments/test.rb
148
+ - spec/dummy/config/initializers/backtrace_silencers.rb
149
+ - spec/dummy/config/initializers/inflections.rb
150
+ - spec/dummy/config/initializers/mime_types.rb
151
+ - spec/dummy/config/initializers/secret_token.rb
152
+ - spec/dummy/config/initializers/session_store.rb
153
+ - spec/dummy/config/initializers/wrap_parameters.rb
154
+ - spec/dummy/config/locales/en.yml
155
+ - spec/dummy/config/routes.rb
156
+ - spec/dummy/config.ru
157
+ - spec/dummy/db/development.sqlite3
158
+ - spec/dummy/db/migrate/20130507231624_create_thing_with_obscured_ids.rb
159
+ - spec/dummy/db/migrate/20130507235114_create_thing_with_configured_obscured_ids.rb
160
+ - spec/dummy/db/schema.rb
161
+ - spec/dummy/db/test.sqlite3
162
+ - spec/dummy/log/development.log
163
+ - spec/dummy/log/test.log
164
+ - spec/dummy/public/404.html
165
+ - spec/dummy/public/422.html
166
+ - spec/dummy/public/500.html
167
+ - spec/dummy/public/favicon.ico
168
+ - spec/dummy/Rakefile
169
+ - spec/dummy/README.rdoc
170
+ - spec/dummy/script/rails
171
+ - spec/Gemfile
172
+ - spec/Gemfile.lock
173
+ - spec/MIT-LICENSE
174
+ - spec/models/thing_with_configured_obscured_id_spec.rb
175
+ - spec/models/thing_with_obscured_id_spec.rb
176
+ - spec/obscured_id.gemspec
177
+ - spec/Rakefile
178
+ - spec/README.md
179
+ - spec/README.rdoc
180
+ - spec/spec_helper.rb