randomized_field 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.md +92 -0
  3. data/Rakefile +37 -0
  4. data/lib/randomized_field.rb +4 -0
  5. data/lib/randomized_field/base.rb +21 -0
  6. data/lib/randomized_field/defaults.rb +8 -0
  7. data/lib/randomized_field/randomizer.rb +31 -0
  8. data/lib/randomized_field/version.rb +4 -0
  9. data/lib/tasks/randomized_field_tasks.rake +4 -0
  10. data/test/dummy/Rakefile +7 -0
  11. data/test/dummy/app/assets/javascripts/application.js +9 -0
  12. data/test/dummy/app/assets/stylesheets/application.css +7 -0
  13. data/test/dummy/app/controllers/application_controller.rb +3 -0
  14. data/test/dummy/app/helpers/application_helper.rb +2 -0
  15. data/test/dummy/app/models/default_model.rb +3 -0
  16. data/test/dummy/app/models/prefix_model.rb +3 -0
  17. data/test/dummy/app/models/single_character_model.rb +3 -0
  18. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  19. data/test/dummy/config.ru +4 -0
  20. data/test/dummy/config/application.rb +45 -0
  21. data/test/dummy/config/boot.rb +10 -0
  22. data/test/dummy/config/database.yml +25 -0
  23. data/test/dummy/config/environment.rb +5 -0
  24. data/test/dummy/config/environments/development.rb +30 -0
  25. data/test/dummy/config/environments/production.rb +60 -0
  26. data/test/dummy/config/environments/test.rb +39 -0
  27. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  28. data/test/dummy/config/initializers/inflections.rb +10 -0
  29. data/test/dummy/config/initializers/mime_types.rb +5 -0
  30. data/test/dummy/config/initializers/secret_token.rb +7 -0
  31. data/test/dummy/config/initializers/session_store.rb +8 -0
  32. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  33. data/test/dummy/config/locales/en.yml +5 -0
  34. data/test/dummy/config/routes.rb +58 -0
  35. data/test/dummy/db/development.sqlite3 +0 -0
  36. data/test/dummy/db/migrate/20120204224641_create_default_models.rb +9 -0
  37. data/test/dummy/db/migrate/20120204235832_create_prefix_models.rb +9 -0
  38. data/test/dummy/db/migrate/20120205000853_create_single_character_models.rb +9 -0
  39. data/test/dummy/db/schema.rb +34 -0
  40. data/test/dummy/db/test.sqlite3 +0 -0
  41. data/test/dummy/log/development.log +269 -0
  42. data/test/dummy/log/test.log +1186 -0
  43. data/test/dummy/public/404.html +26 -0
  44. data/test/dummy/public/422.html +26 -0
  45. data/test/dummy/public/500.html +26 -0
  46. data/test/dummy/public/favicon.ico +0 -0
  47. data/test/dummy/script/rails +6 -0
  48. data/test/dummy/test/fixtures/default_models.yml +7 -0
  49. data/test/dummy/test/fixtures/prefix_models.yml +7 -0
  50. data/test/dummy/test/fixtures/simple_models.yml +7 -0
  51. data/test/dummy/test/fixtures/single_character_models.yml +7 -0
  52. data/test/dummy/test/unit/default_model_test.rb +7 -0
  53. data/test/dummy/test/unit/prefix_model_test.rb +7 -0
  54. data/test/dummy/test/unit/single_character_model_test.rb +7 -0
  55. data/test/randomized_field_test.rb +69 -0
  56. data/test/test_helper.rb +10 -0
  57. metadata +191 -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,26 @@
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
+ <p>We've been notified about this issue and we'll take a look at it shortly.</p>
24
+ </div>
25
+ </body>
26
+ </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,7 @@
1
+ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
2
+
3
+ one:
4
+ dummy_field: MyString
5
+
6
+ two:
7
+ dummy_field: MyString
@@ -0,0 +1,7 @@
1
+ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
2
+
3
+ one:
4
+ dummy_field: MyString
5
+
6
+ two:
7
+ dummy_field: MyString
@@ -0,0 +1,7 @@
1
+ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
2
+
3
+ one:
4
+ dummy_field: MyString
5
+
6
+ two:
7
+ dummy_field: MyString
@@ -0,0 +1,7 @@
1
+ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
2
+
3
+ one:
4
+ dummy_field: MyString
5
+
6
+ two:
7
+ dummy_field: MyString
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class DefaultModelTest < ActiveSupport::TestCase
4
+ # test "the truth" do
5
+ # assert true
6
+ # end
7
+ end
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class PrefixModelTest < ActiveSupport::TestCase
4
+ # test "the truth" do
5
+ # assert true
6
+ # end
7
+ end
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class SingleCharacterModelTest < ActiveSupport::TestCase
4
+ # test "the truth" do
5
+ # assert true
6
+ # end
7
+ end
@@ -0,0 +1,69 @@
1
+ require 'test_helper'
2
+
3
+ class RandomizedFieldTest < ActiveSupport::TestCase
4
+ def setup
5
+ @models = {
6
+ :default_model => DefaultModel.create,
7
+ :prefix_model => PrefixModel.create,
8
+ :single_character_model => SingleCharacterModel.create
9
+ }
10
+ end
11
+
12
+ def teardown
13
+ @models.each { |(model_name, model)| model.destroy }
14
+ end
15
+
16
+ test "truth" do
17
+ assert_kind_of Module, RandomizedField
18
+ assert_kind_of Module, RandomizedField::Base
19
+ assert_kind_of Class, RandomizedField::Randomizer
20
+ end
21
+
22
+ test "DefaultModel should have the default randomized field options set" do
23
+ model = @models[:default_model]
24
+
25
+ field_name = model.class.randomized_field_name
26
+ options = model.class.randomized_field_options
27
+
28
+ assert_equal options[:prefix], RandomizedField::DEFAULTS[:prefix]
29
+ assert_equal options[:length], RandomizedField::DEFAULTS[:length]
30
+ assert_equal options[:valid_characters], RandomizedField::DEFAULTS[:valid_characters]
31
+ end
32
+
33
+ test "The instance of DefaultModel should have the default random field values set" do
34
+ model = @models[:default_model]
35
+
36
+ field_name = model.class.randomized_field_name
37
+
38
+ assert_respond_to model, field_name
39
+ assert model[field_name].present?
40
+ assert_equal model[field_name].length, RandomizedField::DEFAULTS[:length]
41
+
42
+ assert_match /^#{RandomizedField::DEFAULTS[:prefix]}[#{RandomizedField::DEFAULTS[:valid_characters].join("|")}]+$/,
43
+ model[field_name]
44
+ end
45
+
46
+ test "PrefixModel should have a randomized field with a prefix" do
47
+ model = @models[:prefix_model]
48
+
49
+ field_name = model.class.randomized_field_name
50
+ options = model.class.randomized_field_options
51
+
52
+ assert_operator options[:prefix].length, :>, 0
53
+ assert_match /^#{options[:prefix]}/, model[field_name]
54
+ assert_equal model[field_name].length, options[:prefix].length + options[:length]
55
+ end
56
+
57
+ test "SingleCharacterModel should have a randomized field containing a single character" do
58
+ model = @models[:single_character_model]
59
+
60
+ field_name = model.class.randomized_field_name
61
+ options = model.class.randomized_field_options
62
+
63
+ assert_equal options[:valid_characters].length, 1
64
+
65
+ character = options[:valid_characters].first
66
+
67
+ assert_equal model[field_name], character*options[:length]
68
+ end
69
+ end
@@ -0,0 +1,10 @@
1
+ # Configure Rails Environment
2
+ ENV["RAILS_ENV"] = "test"
3
+
4
+ require File.expand_path("../dummy/config/environment.rb", __FILE__)
5
+ require "rails/test_help"
6
+
7
+ Rails.backtrace_cleaner.remove_silencers!
8
+
9
+ # Load support files
10
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
metadata ADDED
@@ -0,0 +1,191 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: randomized_field
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jesse Farmer
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-02-05 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: sqlite3
16
+ requirement: &70320797453040 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70320797453040
25
+ - !ruby/object:Gem::Dependency
26
+ name: rails
27
+ requirement: &70320797452540 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: '3.1'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70320797452540
36
+ - !ruby/object:Gem::Dependency
37
+ name: activerecord
38
+ requirement: &70320797452040 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: '3.1'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70320797452040
47
+ description: ! 'RandomizedField is a simple plugin for ActiveRecord that populates
48
+ a field with a unique,
49
+
50
+ randomly-generated string. This is useful for generating one-off tokens or creating
51
+ a
52
+
53
+ non-incrementing unique ID. See the project page for example uses.
54
+
55
+ '
56
+ email:
57
+ - jesse@20bits.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - lib/randomized_field/base.rb
63
+ - lib/randomized_field/defaults.rb
64
+ - lib/randomized_field/randomizer.rb
65
+ - lib/randomized_field/version.rb
66
+ - lib/randomized_field.rb
67
+ - lib/tasks/randomized_field_tasks.rake
68
+ - MIT-LICENSE
69
+ - Rakefile
70
+ - README.md
71
+ - test/dummy/app/assets/javascripts/application.js
72
+ - test/dummy/app/assets/stylesheets/application.css
73
+ - test/dummy/app/controllers/application_controller.rb
74
+ - test/dummy/app/helpers/application_helper.rb
75
+ - test/dummy/app/models/default_model.rb
76
+ - test/dummy/app/models/prefix_model.rb
77
+ - test/dummy/app/models/single_character_model.rb
78
+ - test/dummy/app/views/layouts/application.html.erb
79
+ - test/dummy/config/application.rb
80
+ - test/dummy/config/boot.rb
81
+ - test/dummy/config/database.yml
82
+ - test/dummy/config/environment.rb
83
+ - test/dummy/config/environments/development.rb
84
+ - test/dummy/config/environments/production.rb
85
+ - test/dummy/config/environments/test.rb
86
+ - test/dummy/config/initializers/backtrace_silencers.rb
87
+ - test/dummy/config/initializers/inflections.rb
88
+ - test/dummy/config/initializers/mime_types.rb
89
+ - test/dummy/config/initializers/secret_token.rb
90
+ - test/dummy/config/initializers/session_store.rb
91
+ - test/dummy/config/initializers/wrap_parameters.rb
92
+ - test/dummy/config/locales/en.yml
93
+ - test/dummy/config/routes.rb
94
+ - test/dummy/config.ru
95
+ - test/dummy/db/development.sqlite3
96
+ - test/dummy/db/migrate/20120204224641_create_default_models.rb
97
+ - test/dummy/db/migrate/20120204235832_create_prefix_models.rb
98
+ - test/dummy/db/migrate/20120205000853_create_single_character_models.rb
99
+ - test/dummy/db/schema.rb
100
+ - test/dummy/db/test.sqlite3
101
+ - test/dummy/log/development.log
102
+ - test/dummy/log/test.log
103
+ - test/dummy/public/404.html
104
+ - test/dummy/public/422.html
105
+ - test/dummy/public/500.html
106
+ - test/dummy/public/favicon.ico
107
+ - test/dummy/Rakefile
108
+ - test/dummy/script/rails
109
+ - test/dummy/test/fixtures/default_models.yml
110
+ - test/dummy/test/fixtures/prefix_models.yml
111
+ - test/dummy/test/fixtures/simple_models.yml
112
+ - test/dummy/test/fixtures/single_character_models.yml
113
+ - test/dummy/test/unit/default_model_test.rb
114
+ - test/dummy/test/unit/prefix_model_test.rb
115
+ - test/dummy/test/unit/single_character_model_test.rb
116
+ - test/randomized_field_test.rb
117
+ - test/test_helper.rb
118
+ homepage: http://github.com/jfarmer/randomzied_field
119
+ licenses: []
120
+ post_install_message:
121
+ rdoc_options: []
122
+ require_paths:
123
+ - lib
124
+ required_ruby_version: !ruby/object:Gem::Requirement
125
+ none: false
126
+ requirements:
127
+ - - ! '>='
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ required_rubygems_version: !ruby/object:Gem::Requirement
131
+ none: false
132
+ requirements:
133
+ - - ! '>='
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ requirements: []
137
+ rubyforge_project:
138
+ rubygems_version: 1.8.10
139
+ signing_key:
140
+ specification_version: 3
141
+ summary: An ActiveRecord plugin to populate a database field with a unique, randomly-generated
142
+ string
143
+ test_files:
144
+ - test/dummy/app/assets/javascripts/application.js
145
+ - test/dummy/app/assets/stylesheets/application.css
146
+ - test/dummy/app/controllers/application_controller.rb
147
+ - test/dummy/app/helpers/application_helper.rb
148
+ - test/dummy/app/models/default_model.rb
149
+ - test/dummy/app/models/prefix_model.rb
150
+ - test/dummy/app/models/single_character_model.rb
151
+ - test/dummy/app/views/layouts/application.html.erb
152
+ - test/dummy/config/application.rb
153
+ - test/dummy/config/boot.rb
154
+ - test/dummy/config/database.yml
155
+ - test/dummy/config/environment.rb
156
+ - test/dummy/config/environments/development.rb
157
+ - test/dummy/config/environments/production.rb
158
+ - test/dummy/config/environments/test.rb
159
+ - test/dummy/config/initializers/backtrace_silencers.rb
160
+ - test/dummy/config/initializers/inflections.rb
161
+ - test/dummy/config/initializers/mime_types.rb
162
+ - test/dummy/config/initializers/secret_token.rb
163
+ - test/dummy/config/initializers/session_store.rb
164
+ - test/dummy/config/initializers/wrap_parameters.rb
165
+ - test/dummy/config/locales/en.yml
166
+ - test/dummy/config/routes.rb
167
+ - test/dummy/config.ru
168
+ - test/dummy/db/development.sqlite3
169
+ - test/dummy/db/migrate/20120204224641_create_default_models.rb
170
+ - test/dummy/db/migrate/20120204235832_create_prefix_models.rb
171
+ - test/dummy/db/migrate/20120205000853_create_single_character_models.rb
172
+ - test/dummy/db/schema.rb
173
+ - test/dummy/db/test.sqlite3
174
+ - test/dummy/log/development.log
175
+ - test/dummy/log/test.log
176
+ - test/dummy/public/404.html
177
+ - test/dummy/public/422.html
178
+ - test/dummy/public/500.html
179
+ - test/dummy/public/favicon.ico
180
+ - test/dummy/Rakefile
181
+ - test/dummy/script/rails
182
+ - test/dummy/test/fixtures/default_models.yml
183
+ - test/dummy/test/fixtures/prefix_models.yml
184
+ - test/dummy/test/fixtures/simple_models.yml
185
+ - test/dummy/test/fixtures/single_character_models.yml
186
+ - test/dummy/test/unit/default_model_test.rb
187
+ - test/dummy/test/unit/prefix_model_test.rb
188
+ - test/dummy/test/unit/single_character_model_test.rb
189
+ - test/randomized_field_test.rb
190
+ - test/test_helper.rb
191
+ has_rdoc: