has_moderated 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.rdoc +75 -0
  3. data/Rakefile +37 -0
  4. data/lib/generators/USAGE +9 -0
  5. data/lib/generators/has_moderated/install/install_generator.rb +24 -0
  6. data/lib/generators/has_moderated/install/templates/migration.rb +15 -0
  7. data/lib/generators/has_moderated/install/templates/moderation.rb +60 -0
  8. data/lib/has_moderated/version.rb +3 -0
  9. data/lib/has_moderated.rb +128 -0
  10. data/lib/tasks/has_moderated_tasks.rake +4 -0
  11. data/test/dummy/Rakefile +7 -0
  12. data/test/dummy/app/assets/javascripts/application.js +9 -0
  13. data/test/dummy/app/assets/stylesheets/application.css +7 -0
  14. data/test/dummy/app/controllers/application_controller.rb +3 -0
  15. data/test/dummy/app/helpers/application_helper.rb +2 -0
  16. data/test/dummy/app/models/moderation.rb +60 -0
  17. data/test/dummy/app/models/subtask.rb +3 -0
  18. data/test/dummy/app/models/task.rb +6 -0
  19. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  20. data/test/dummy/config/application.rb +50 -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 +42 -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/config.ru +4 -0
  36. data/test/dummy/db/development.sqlite3 +0 -0
  37. data/test/dummy/db/migrate/20110901013205_create_tasks.rb +10 -0
  38. data/test/dummy/db/migrate/20110901013228_create_subtasks.rb +11 -0
  39. data/test/dummy/db/migrate/20110901013618_create_moderations.rb +15 -0
  40. data/test/dummy/db/schema.rb +39 -0
  41. data/test/dummy/db/test.sqlite3 +0 -0
  42. data/test/dummy/log/development.log +422 -0
  43. data/test/dummy/log/test.log +2504 -0
  44. data/test/dummy/public/404.html +26 -0
  45. data/test/dummy/public/422.html +26 -0
  46. data/test/dummy/public/500.html +26 -0
  47. data/test/dummy/public/favicon.ico +0 -0
  48. data/test/dummy/script/rails +6 -0
  49. data/test/dummy/spec/models/task_spec.rb +115 -0
  50. data/test/dummy/spec/spec_helper.rb +27 -0
  51. metadata +185 -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,115 @@
1
+ require 'spec_helper'
2
+
3
+ describe Task do
4
+ it "doesn't store new tasks in the database, but in moderations" do
5
+ Task.create! :title => "Bye Bye"
6
+ Task.count.should eq(0)
7
+ Moderation.count.should eq(1)
8
+ end
9
+
10
+ it "restores a new record properly from an accepted moderation and the moderation is removed" do
11
+ Task.create! :title => "Bye Bye"
12
+ Moderation.last.accept
13
+
14
+ Moderation.count.should eq(0)
15
+ Task.count.should eq(1)
16
+
17
+ t = Task.last
18
+ t.title.should eq("Bye Bye")
19
+ end
20
+
21
+ it "doesn't store updated moderated attributes in the database, but in moderations" do
22
+ Task.create! :title => "Bye Bye"
23
+ Moderation.last.accept
24
+
25
+ # test different ways (will generate more than one moderation)
26
+ # 1
27
+ Task.last.update_attributes(:title => "Hollywood Hills")
28
+ # 2
29
+ t = Task.last
30
+ t.title = "Hollywood Hills"
31
+ t.save
32
+ # 3
33
+ Task.last.update_attribute(:title, "Hollywood Hills")
34
+ # 4
35
+ t = Task.last
36
+ t.attributes = { :title => "Hollywood Hills" }
37
+ t.save
38
+
39
+ Moderation.count.should eq(4)
40
+
41
+ Task.last.title.should eq("Bye Bye")
42
+ Moderation.last.accept
43
+ Task.last.title.should eq("Hollywood Hills")
44
+ Task.count.should eq(1)
45
+ end
46
+
47
+ it "properly discards a create moderation" do
48
+ Task.create! :title => "Bye Bye"
49
+ Moderation.last.discard
50
+
51
+ Task.count.should eq(0)
52
+ Moderation.count.should eq(0)
53
+ end
54
+
55
+ it "properly discards an update moderation" do
56
+ Task.create! :title => "Bye Bye"
57
+ Moderation.last.accept
58
+
59
+ Task.last.update_attributes(:title => "Hollywood Hills")
60
+
61
+ Moderation.last.discard
62
+
63
+ Task.count.should eq(1)
64
+ Task.last.title.should eq("Bye Bye")
65
+ Moderation.count.should eq(0)
66
+ end
67
+
68
+ it "properly stores an associated subtask in moderations" do
69
+ t = Task.new :title => "Bye Bye"
70
+ t.subtasks.build :title => "Hollywood Hills"
71
+ t.save
72
+
73
+ Task.count.should eq(0)
74
+ Subtask.count.should eq(0)
75
+
76
+ Moderation.last.accept
77
+ Moderation.count.should eq(0)
78
+
79
+ t = Task.last
80
+ t.title.should eq("Bye Bye")
81
+ t.subtasks.count.should eq(1)
82
+ t.subtasks.first.title.should eq("Hollywood Hills")
83
+ end
84
+
85
+ it "bypasses attr_accessible when applying a create moderation" do
86
+ # desc is not attr_accessible, can't use mass assign to create
87
+ t = Task.new :title => "Bye Bye"
88
+ t.desc = "Hollywood Hills"
89
+ t.save
90
+
91
+ Moderation.count.should eq(1)
92
+
93
+ Moderation.last.accept
94
+
95
+ Moderation.count.should eq(0)
96
+ Task.last.title.should eq("Bye Bye") # just so we know it's created properly
97
+ Task.last.desc.should eq("Hollywood Hills")
98
+ end
99
+
100
+ it "bypasses attr_accessible when applying an update moderation" do
101
+ Task.create! :title => "Bye Bye"
102
+ Moderation.last.accept
103
+
104
+ # desc is not attr_accessible
105
+ t = Task.last
106
+ t.desc = "Hollywood Hills"
107
+ t.save
108
+
109
+ Moderation.count.should eq(1)
110
+
111
+ Task.last.desc.should be_nil
112
+ Moderation.last.accept
113
+ Task.last.desc.should eq("Hollywood Hills")
114
+ end
115
+ end
@@ -0,0 +1,27 @@
1
+ # This file is copied to spec/ when you run 'rails generate rspec:install'
2
+ ENV["RAILS_ENV"] ||= 'test'
3
+ require File.expand_path("../../config/environment", __FILE__)
4
+ require 'rspec/rails'
5
+
6
+ # Requires supporting ruby files with custom matchers and macros, etc,
7
+ # in spec/support/ and its subdirectories.
8
+ Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
11
+ # == Mock Framework
12
+ #
13
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
14
+ #
15
+ # config.mock_with :mocha
16
+ # config.mock_with :flexmock
17
+ # config.mock_with :rr
18
+ config.mock_with :rspec
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
+ end
metadata ADDED
@@ -0,0 +1,185 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: has_moderated
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Jan Berdajs
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-09-01 00:00:00 +02:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ hash: 3
28
+ segments:
29
+ - 3
30
+ - 1
31
+ - 0
32
+ version: 3.1.0
33
+ version_requirements: *id001
34
+ name: rails
35
+ prerelease: false
36
+ type: :runtime
37
+ - !ruby/object:Gem::Dependency
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
46
+ version: "0"
47
+ version_requirements: *id002
48
+ name: sqlite3
49
+ prerelease: false
50
+ type: :development
51
+ description: Moderated fields or whole model instances are serialized and saved into a separate moderations table. The moderation can then be accepted and the changes will be applied to the model. This way, lookups for existing, accepted fields or entries will be much faster than if using something like Papertrail, since the changes that have not yet been accepted are stored outside of the model table - in the moderations table.
52
+ email:
53
+ - mrbrdo@gmail.com
54
+ executables: []
55
+
56
+ extensions: []
57
+
58
+ extra_rdoc_files: []
59
+
60
+ files:
61
+ - lib/has_moderated.rb
62
+ - lib/tasks/has_moderated_tasks.rake
63
+ - lib/has_moderated/version.rb
64
+ - lib/generators/has_moderated/install/install_generator.rb
65
+ - lib/generators/has_moderated/install/templates/migration.rb
66
+ - lib/generators/has_moderated/install/templates/moderation.rb
67
+ - lib/generators/USAGE
68
+ - MIT-LICENSE
69
+ - Rakefile
70
+ - README.rdoc
71
+ - test/dummy/log/development.log
72
+ - test/dummy/log/test.log
73
+ - test/dummy/config/boot.rb
74
+ - test/dummy/config/environment.rb
75
+ - test/dummy/config/locales/en.yml
76
+ - test/dummy/config/initializers/mime_types.rb
77
+ - test/dummy/config/initializers/session_store.rb
78
+ - test/dummy/config/initializers/backtrace_silencers.rb
79
+ - test/dummy/config/initializers/wrap_parameters.rb
80
+ - test/dummy/config/initializers/inflections.rb
81
+ - test/dummy/config/initializers/secret_token.rb
82
+ - test/dummy/config/application.rb
83
+ - test/dummy/config/database.yml
84
+ - test/dummy/config/routes.rb
85
+ - test/dummy/config/environments/production.rb
86
+ - test/dummy/config/environments/test.rb
87
+ - test/dummy/config/environments/development.rb
88
+ - test/dummy/script/rails
89
+ - test/dummy/db/schema.rb
90
+ - test/dummy/db/development.sqlite3
91
+ - test/dummy/db/migrate/20110901013228_create_subtasks.rb
92
+ - test/dummy/db/migrate/20110901013205_create_tasks.rb
93
+ - test/dummy/db/migrate/20110901013618_create_moderations.rb
94
+ - test/dummy/db/test.sqlite3
95
+ - test/dummy/app/helpers/application_helper.rb
96
+ - test/dummy/app/models/task.rb
97
+ - test/dummy/app/models/moderation.rb
98
+ - test/dummy/app/models/subtask.rb
99
+ - test/dummy/app/assets/stylesheets/application.css
100
+ - test/dummy/app/assets/javascripts/application.js
101
+ - test/dummy/app/controllers/application_controller.rb
102
+ - test/dummy/app/views/layouts/application.html.erb
103
+ - test/dummy/spec/models/task_spec.rb
104
+ - test/dummy/spec/spec_helper.rb
105
+ - test/dummy/config.ru
106
+ - test/dummy/Rakefile
107
+ - test/dummy/public/500.html
108
+ - test/dummy/public/404.html
109
+ - test/dummy/public/favicon.ico
110
+ - test/dummy/public/422.html
111
+ has_rdoc: true
112
+ homepage: http://www.mrbrdo.net/
113
+ licenses: []
114
+
115
+ post_install_message:
116
+ rdoc_options: []
117
+
118
+ require_paths:
119
+ - lib
120
+ required_ruby_version: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ hash: 3
126
+ segments:
127
+ - 0
128
+ version: "0"
129
+ required_rubygems_version: !ruby/object:Gem::Requirement
130
+ none: false
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ hash: 3
135
+ segments:
136
+ - 0
137
+ version: "0"
138
+ requirements: []
139
+
140
+ rubyforge_project:
141
+ rubygems_version: 1.6.2
142
+ signing_key:
143
+ specification_version: 3
144
+ summary: Moderate fields or entire model instances.
145
+ test_files:
146
+ - test/dummy/log/development.log
147
+ - test/dummy/log/test.log
148
+ - test/dummy/config/boot.rb
149
+ - test/dummy/config/environment.rb
150
+ - test/dummy/config/locales/en.yml
151
+ - test/dummy/config/initializers/mime_types.rb
152
+ - test/dummy/config/initializers/session_store.rb
153
+ - test/dummy/config/initializers/backtrace_silencers.rb
154
+ - test/dummy/config/initializers/wrap_parameters.rb
155
+ - test/dummy/config/initializers/inflections.rb
156
+ - test/dummy/config/initializers/secret_token.rb
157
+ - test/dummy/config/application.rb
158
+ - test/dummy/config/database.yml
159
+ - test/dummy/config/routes.rb
160
+ - test/dummy/config/environments/production.rb
161
+ - test/dummy/config/environments/test.rb
162
+ - test/dummy/config/environments/development.rb
163
+ - test/dummy/script/rails
164
+ - test/dummy/db/schema.rb
165
+ - test/dummy/db/development.sqlite3
166
+ - test/dummy/db/migrate/20110901013228_create_subtasks.rb
167
+ - test/dummy/db/migrate/20110901013205_create_tasks.rb
168
+ - test/dummy/db/migrate/20110901013618_create_moderations.rb
169
+ - test/dummy/db/test.sqlite3
170
+ - test/dummy/app/helpers/application_helper.rb
171
+ - test/dummy/app/models/task.rb
172
+ - test/dummy/app/models/moderation.rb
173
+ - test/dummy/app/models/subtask.rb
174
+ - test/dummy/app/assets/stylesheets/application.css
175
+ - test/dummy/app/assets/javascripts/application.js
176
+ - test/dummy/app/controllers/application_controller.rb
177
+ - test/dummy/app/views/layouts/application.html.erb
178
+ - test/dummy/spec/models/task_spec.rb
179
+ - test/dummy/spec/spec_helper.rb
180
+ - test/dummy/config.ru
181
+ - test/dummy/Rakefile
182
+ - test/dummy/public/500.html
183
+ - test/dummy/public/404.html
184
+ - test/dummy/public/favicon.ico
185
+ - test/dummy/public/422.html