userstamper 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +4 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +35 -0
  5. data/CHANGELOG.md +116 -0
  6. data/Gemfile +3 -0
  7. data/Gemfile.lock +222 -0
  8. data/LICENSE +22 -0
  9. data/README.md +142 -0
  10. data/lib/userstamper.rb +23 -0
  11. data/lib/userstamper/configuration.rb +40 -0
  12. data/lib/userstamper/controller_concern.rb +44 -0
  13. data/lib/userstamper/migration_concern.rb +9 -0
  14. data/lib/userstamper/model_concern.rb +6 -0
  15. data/lib/userstamper/railtie.rb +15 -0
  16. data/lib/userstamper/stampable.rb +106 -0
  17. data/lib/userstamper/stamper.rb +54 -0
  18. data/lib/userstamper/utilities.rb +57 -0
  19. data/spec/controllers/posts_controller_spec.rb +44 -0
  20. data/spec/controllers/users_controller_spec.rb +50 -0
  21. data/spec/coverage_helper.rb +58 -0
  22. data/spec/dummy/README.rdoc +28 -0
  23. data/spec/dummy/Rakefile +6 -0
  24. data/spec/dummy/app/assets/config/manifest.js +0 -0
  25. data/spec/dummy/app/assets/images/.keep +0 -0
  26. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  27. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  28. data/spec/dummy/app/controllers/application_controller.rb +13 -0
  29. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  30. data/spec/dummy/app/controllers/posts_controller.rb +36 -0
  31. data/spec/dummy/app/controllers/users_controller.rb +22 -0
  32. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  33. data/spec/dummy/app/mailers/.keep +0 -0
  34. data/spec/dummy/app/models/comment.rb +5 -0
  35. data/spec/dummy/app/models/concerns/.keep +0 -0
  36. data/spec/dummy/app/models/person.rb +3 -0
  37. data/spec/dummy/app/models/post.rb +6 -0
  38. data/spec/dummy/app/models/tag.rb +3 -0
  39. data/spec/dummy/app/models/user.rb +3 -0
  40. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  41. data/spec/dummy/bin/bundle +3 -0
  42. data/spec/dummy/bin/rails +4 -0
  43. data/spec/dummy/bin/rake +4 -0
  44. data/spec/dummy/bin/setup +29 -0
  45. data/spec/dummy/config.ru +4 -0
  46. data/spec/dummy/config/application.rb +12 -0
  47. data/spec/dummy/config/boot.rb +5 -0
  48. data/spec/dummy/config/database.yml +23 -0
  49. data/spec/dummy/config/environment.rb +5 -0
  50. data/spec/dummy/config/environments/development.rb +41 -0
  51. data/spec/dummy/config/environments/production.rb +79 -0
  52. data/spec/dummy/config/environments/test.rb +37 -0
  53. data/spec/dummy/config/initializers/assets.rb +11 -0
  54. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  55. data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
  56. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  57. data/spec/dummy/config/initializers/inflections.rb +16 -0
  58. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  59. data/spec/dummy/config/initializers/session_store.rb +3 -0
  60. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  61. data/spec/dummy/config/locales/en.yml +23 -0
  62. data/spec/dummy/config/routes.rb +56 -0
  63. data/spec/dummy/config/secrets.yml +22 -0
  64. data/spec/dummy/lib/assets/.keep +0 -0
  65. data/spec/dummy/log/.keep +0 -0
  66. data/spec/dummy/public/404.html +67 -0
  67. data/spec/dummy/public/422.html +67 -0
  68. data/spec/dummy/public/500.html +66 -0
  69. data/spec/dummy/public/favicon.ico +0 -0
  70. data/spec/lib/configuration_spec.rb +20 -0
  71. data/spec/lib/migration_spec.rb +60 -0
  72. data/spec/lib/stamper_spec.rb +66 -0
  73. data/spec/lib/stamping_spec.rb +235 -0
  74. data/spec/lib/userstamp_spec.rb +4 -0
  75. data/spec/rails_helper.rb +7 -0
  76. data/spec/spec_helper.rb +98 -0
  77. data/spec/support/database_helpers.rb +73 -0
  78. data/spec/support/with_temporary_table.rb +51 -0
  79. data/userstamper.gemspec +46 -0
  80. metadata +279 -0
@@ -0,0 +1,73 @@
1
+ def define_first_post
2
+ @first_post = Post.create!(title: 'a title')
3
+ end
4
+
5
+ RSpec.configure do |config|
6
+ config.before(:suite) do
7
+ ActiveRecord::Migration.class_eval do
8
+ # Users are created and updated by other Users
9
+ create_table :users, :force => true do |t|
10
+ t.column :name, :string
11
+ t.column :creator_id, :integer
12
+ t.column :created_on, :datetime
13
+ t.column :updater_id, :integer
14
+ t.column :updated_at, :datetime
15
+ end
16
+
17
+ # People are created and updated by Users
18
+ create_table :people, :force => true do |t|
19
+ t.column :name, :string
20
+ t.column :creator_id, :integer
21
+ t.column :created_on, :datetime
22
+ t.column :updater_id, :integer
23
+ t.column :updated_at, :datetime
24
+ end
25
+
26
+ # Posts are created and updated by People
27
+ create_table :posts, :force => true do |t|
28
+ t.column :title, :string
29
+ t.column :creator_id, :integer
30
+ t.column :created_on, :datetime
31
+ t.column :updater_id, :integer
32
+ t.column :updated_at, :datetime
33
+ end
34
+
35
+ # Comments are created and updated by People
36
+ # and also use non-standard foreign keys.
37
+ create_table :comments, :force => true do |t|
38
+ t.column :post_id, :integer
39
+ t.column :comment, :string
40
+ t.column :created_by, :integer
41
+ t.column :created_at, :datetime
42
+ t.column :updated_by, :integer
43
+ t.column :updated_at, :datetime
44
+ end
45
+
46
+ create_table :tags, force: true do |t|
47
+ t.column :title, :string
48
+ end
49
+
50
+ create_table :post_tags, force: true do |t|
51
+ t.column :post_id, :integer
52
+ t.column :tag_id, :integer
53
+ end
54
+ end
55
+ end
56
+
57
+ config.before(:each) do
58
+ User.delete_all
59
+ Person.delete_all
60
+ Post.delete_all
61
+ Comment.delete_all
62
+ User.reset_stamper
63
+ Person.reset_stamper
64
+
65
+ @zeus = User.create!(name: 'Zeus')
66
+ @hera = User.create!(name: 'Hera')
67
+ User.stamper = @zeus.id
68
+
69
+ @delynn = Person.create!(name: 'Delynn')
70
+ @nicole = Person.create!(name: 'Nicole')
71
+ Person.stamper = @delynn.id
72
+ end
73
+ end
@@ -0,0 +1,51 @@
1
+ # Test group helpers for creating tables.
2
+ # The latest version can be gound at https://gist.github.com/lowjoel/bda0d44b48aac2925079
3
+ module ActiveRecord::TemporaryTable; end
4
+ module ActiveRecord::TemporaryTable::TestGroupHelpers
5
+ # Defines a temporary table that is instantiated when needed, within a `with_temporary_table`
6
+ # block.
7
+ #
8
+ # @param [Symbol] table_name The name of the table to define.
9
+ # @param [Proc] proc The table definition, same as that of a block given to
10
+ # +ActiveRecord::Migration::create_table+
11
+ def temporary_table(table_name, &proc)
12
+ define_method(table_name) do
13
+ proc
14
+ end
15
+ end
16
+
17
+ # Using the temporary table defined previously, run the examples in this group.
18
+ #
19
+ # @param [Symbol] table_name The name of the table to use.
20
+ # @param [Symbol] create_at When to create the table. Defaults to :context.
21
+ # @param [Proc] proc The examples requiring the use of the temporary table.
22
+ def with_temporary_table(table_name, create_at = :context, &proc)
23
+ context "with temporary table #{table_name}" do |*params|
24
+ before(create_at) do
25
+ ActiveRecord::TemporaryTable::TestGroupHelpers.create_table(table_name, send(table_name))
26
+ end
27
+
28
+ after(create_at) do
29
+ ActiveRecord::TemporaryTable::TestGroupHelpers.drop_table(table_name)
30
+ end
31
+
32
+ module_exec(*params, &proc)
33
+ end
34
+ end
35
+
36
+ def self.create_table(table_name, table_definition)
37
+ ActiveRecord::Migration.suppress_messages do
38
+ ActiveRecord::Migration.create_table(table_name, &table_definition)
39
+ end
40
+ end
41
+
42
+ def self.drop_table(table_name)
43
+ ActiveRecord::Migration.suppress_messages do
44
+ ActiveRecord::Migration.drop_table(table_name)
45
+ end
46
+ end
47
+ end
48
+
49
+ RSpec.configure do |config|
50
+ config.extend ActiveRecord::TemporaryTable::TestGroupHelpers, type: :model
51
+ end
@@ -0,0 +1,46 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'userstamper'
7
+ s.version = '4.0.0'
8
+ s.authors = ['Joel Low', 'Priit Tark']
9
+ s.email = ['joel@joelsplace.sg', 'priit@gitlab.eu']
10
+
11
+ s.summary = 'Adds magic creator and updater attributes to your ActiveRecord models.'
12
+ s.description = 'This gem extends ActiveRecord::Base to add automatic updating of created_by and updated_by attributes of your models in much the same way that the ActiveRecord::Timestamp module updates created_(at/on) and updated_(at/on) attributes.'
13
+ s.homepage = 'https://github.com/gitlabeu/userstamp'
14
+ s.license = 'MIT'
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
19
+ s.require_paths = ['lib']
20
+
21
+ if ENV['CI'] == 'true'
22
+ rails_version =
23
+ case ENV['RAILS_VERSION']
24
+ when nil, ''
25
+ '>= 6'
26
+ else
27
+ "~> #{ENV['RAILS_VERSION']}"
28
+ end
29
+ else
30
+ rails_version = '>= 6'
31
+ end
32
+
33
+ s.add_dependency 'rails', rails_version
34
+
35
+ s.add_development_dependency 'tzinfo-data' if RUBY_PLATFORM =~ /mswin|mingw/
36
+ s.add_development_dependency 'rake'
37
+ s.add_development_dependency 'rdoc'
38
+ s.add_development_dependency 'rspec'
39
+ s.add_development_dependency 'rspec-instafail'
40
+ s.add_development_dependency 'rspec-rails', '>= 3.3'
41
+ s.add_development_dependency 'simplecov'
42
+ s.add_development_dependency 'coveralls'
43
+ s.add_development_dependency 'codeclimate-test-reporter'
44
+ s.add_development_dependency 'sqlite3'
45
+ s.add_development_dependency 'pry'
46
+ end
metadata ADDED
@@ -0,0 +1,279 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: userstamper
3
+ version: !ruby/object:Gem::Version
4
+ version: 4.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Joel Low
8
+ - Priit Tark
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2021-04-12 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '6'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '6'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rdoc
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: rspec
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: rspec-instafail
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: rspec-rails
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '3.3'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '3.3'
98
+ - !ruby/object:Gem::Dependency
99
+ name: simplecov
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ - !ruby/object:Gem::Dependency
113
+ name: coveralls
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: codeclimate-test-reporter
128
+ requirement: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ type: :development
134
+ prerelease: false
135
+ version_requirements: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ - !ruby/object:Gem::Dependency
141
+ name: sqlite3
142
+ requirement: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ type: :development
148
+ prerelease: false
149
+ version_requirements: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - ">="
152
+ - !ruby/object:Gem::Version
153
+ version: '0'
154
+ - !ruby/object:Gem::Dependency
155
+ name: pry
156
+ requirement: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - ">="
159
+ - !ruby/object:Gem::Version
160
+ version: '0'
161
+ type: :development
162
+ prerelease: false
163
+ version_requirements: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - ">="
166
+ - !ruby/object:Gem::Version
167
+ version: '0'
168
+ description: This gem extends ActiveRecord::Base to add automatic updating of created_by
169
+ and updated_by attributes of your models in much the same way that the ActiveRecord::Timestamp
170
+ module updates created_(at/on) and updated_(at/on) attributes.
171
+ email:
172
+ - joel@joelsplace.sg
173
+ - priit@gitlab.eu
174
+ executables: []
175
+ extensions: []
176
+ extra_rdoc_files: []
177
+ files:
178
+ - ".gitignore"
179
+ - ".rspec"
180
+ - ".travis.yml"
181
+ - CHANGELOG.md
182
+ - Gemfile
183
+ - Gemfile.lock
184
+ - LICENSE
185
+ - README.md
186
+ - lib/userstamper.rb
187
+ - lib/userstamper/configuration.rb
188
+ - lib/userstamper/controller_concern.rb
189
+ - lib/userstamper/migration_concern.rb
190
+ - lib/userstamper/model_concern.rb
191
+ - lib/userstamper/railtie.rb
192
+ - lib/userstamper/stampable.rb
193
+ - lib/userstamper/stamper.rb
194
+ - lib/userstamper/utilities.rb
195
+ - spec/controllers/posts_controller_spec.rb
196
+ - spec/controllers/users_controller_spec.rb
197
+ - spec/coverage_helper.rb
198
+ - spec/dummy/README.rdoc
199
+ - spec/dummy/Rakefile
200
+ - spec/dummy/app/assets/config/manifest.js
201
+ - spec/dummy/app/assets/images/.keep
202
+ - spec/dummy/app/assets/javascripts/application.js
203
+ - spec/dummy/app/assets/stylesheets/application.css
204
+ - spec/dummy/app/controllers/application_controller.rb
205
+ - spec/dummy/app/controllers/concerns/.keep
206
+ - spec/dummy/app/controllers/posts_controller.rb
207
+ - spec/dummy/app/controllers/users_controller.rb
208
+ - spec/dummy/app/helpers/application_helper.rb
209
+ - spec/dummy/app/mailers/.keep
210
+ - spec/dummy/app/models/comment.rb
211
+ - spec/dummy/app/models/concerns/.keep
212
+ - spec/dummy/app/models/person.rb
213
+ - spec/dummy/app/models/post.rb
214
+ - spec/dummy/app/models/tag.rb
215
+ - spec/dummy/app/models/user.rb
216
+ - spec/dummy/app/views/layouts/application.html.erb
217
+ - spec/dummy/bin/bundle
218
+ - spec/dummy/bin/rails
219
+ - spec/dummy/bin/rake
220
+ - spec/dummy/bin/setup
221
+ - spec/dummy/config.ru
222
+ - spec/dummy/config/application.rb
223
+ - spec/dummy/config/boot.rb
224
+ - spec/dummy/config/database.yml
225
+ - spec/dummy/config/environment.rb
226
+ - spec/dummy/config/environments/development.rb
227
+ - spec/dummy/config/environments/production.rb
228
+ - spec/dummy/config/environments/test.rb
229
+ - spec/dummy/config/initializers/assets.rb
230
+ - spec/dummy/config/initializers/backtrace_silencers.rb
231
+ - spec/dummy/config/initializers/cookies_serializer.rb
232
+ - spec/dummy/config/initializers/filter_parameter_logging.rb
233
+ - spec/dummy/config/initializers/inflections.rb
234
+ - spec/dummy/config/initializers/mime_types.rb
235
+ - spec/dummy/config/initializers/session_store.rb
236
+ - spec/dummy/config/initializers/wrap_parameters.rb
237
+ - spec/dummy/config/locales/en.yml
238
+ - spec/dummy/config/routes.rb
239
+ - spec/dummy/config/secrets.yml
240
+ - spec/dummy/lib/assets/.keep
241
+ - spec/dummy/log/.keep
242
+ - spec/dummy/public/404.html
243
+ - spec/dummy/public/422.html
244
+ - spec/dummy/public/500.html
245
+ - spec/dummy/public/favicon.ico
246
+ - spec/lib/configuration_spec.rb
247
+ - spec/lib/migration_spec.rb
248
+ - spec/lib/stamper_spec.rb
249
+ - spec/lib/stamping_spec.rb
250
+ - spec/lib/userstamp_spec.rb
251
+ - spec/rails_helper.rb
252
+ - spec/spec_helper.rb
253
+ - spec/support/database_helpers.rb
254
+ - spec/support/with_temporary_table.rb
255
+ - userstamper.gemspec
256
+ homepage: https://github.com/gitlabeu/userstamp
257
+ licenses:
258
+ - MIT
259
+ metadata: {}
260
+ post_install_message:
261
+ rdoc_options: []
262
+ require_paths:
263
+ - lib
264
+ required_ruby_version: !ruby/object:Gem::Requirement
265
+ requirements:
266
+ - - ">="
267
+ - !ruby/object:Gem::Version
268
+ version: '0'
269
+ required_rubygems_version: !ruby/object:Gem::Requirement
270
+ requirements:
271
+ - - ">="
272
+ - !ruby/object:Gem::Version
273
+ version: '0'
274
+ requirements: []
275
+ rubygems_version: 3.1.4
276
+ signing_key:
277
+ specification_version: 4
278
+ summary: Adds magic creator and updater attributes to your ActiveRecord models.
279
+ test_files: []