has_moderated 0.0.9 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +12 -0
- data/lib/generators/has_moderated/install/templates/moderation.rb +2 -73
- data/lib/has_moderated/carrier_wave.rb +67 -0
- data/lib/has_moderated/moderation_model.rb +106 -0
- data/lib/has_moderated/version.rb +1 -1
- data/lib/has_moderated.rb +21 -4
- data/test/dummy/app/models/moderation.rb +2 -73
- data/test/dummy/app/models/photo.rb +6 -0
- data/test/dummy/app/models/task.rb +2 -1
- data/test/dummy/app/models/task_photo.rb +5 -0
- data/test/dummy/app/uploaders/generic_uploader.rb +49 -0
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/db/migrate/20111003205633_create_photos.rb +9 -0
- data/test/dummy/db/migrate/20111003234101_create_task_photos.rb +10 -0
- data/test/dummy/db/schema.rb +14 -1
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/falaf/test.rb +0 -0
- data/test/dummy/log/development.log +628 -1251
- data/test/dummy/log/test.log +8473 -10270
- data/test/dummy/public/uploads/task_photo/photo/logo_arnes.gif +0 -0
- data/test/dummy/spec/factories/photos.rb +7 -0
- data/test/dummy/spec/factories/task_photos.rb +7 -0
- data/test/dummy/spec/models/photo_spec.rb +67 -0
- data/test/dummy/spec/models/task_photo_spec.rb +31 -0
- data/test/dummy/spec/models/task_spec.rb +1 -1
- metadata +97 -73
Binary file
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
def dirEmpty? dirname
|
5
|
+
return true unless File.directory?(dirname)
|
6
|
+
Dir.entries(dirname).size == 2
|
7
|
+
end
|
8
|
+
|
9
|
+
tempdir = File.expand_path("../../../public/uploads/tmp", __FILE__)
|
10
|
+
uploaddir = "/Users/apple/rails/has_moderated/test/dummy/public/uploads/photo/photo/1"
|
11
|
+
SAMPLE_PHOTO_URL = "http://www.arnes.si/typo3conf/ext/ag_arnes_eff_template/templates/template-index/images/logo_arnes.gif"
|
12
|
+
|
13
|
+
describe Photo do
|
14
|
+
before(:each) do
|
15
|
+
FileUtils.rm_rf(tempdir) # remove temp dir
|
16
|
+
FileUtils.rm_rf(File.expand_path("../../../public/uploads", __FILE__)) # remove uploads dir
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should upload photo" do
|
20
|
+
photo = Photo.create!(:remote_photo_url => SAMPLE_PHOTO_URL)
|
21
|
+
|
22
|
+
Photo.count.should eq(0)
|
23
|
+
dirEmpty?(tempdir).should be_false
|
24
|
+
Moderation.last.accept
|
25
|
+
dirEmpty?(tempdir).should be_true
|
26
|
+
|
27
|
+
Photo.count.should eq(1)
|
28
|
+
photo = Photo.first
|
29
|
+
photo.photo.should_not be_nil
|
30
|
+
photo.photo.file.should_not be_nil
|
31
|
+
photo.photo.file.file.should_not be_nil
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should delete temp files if discarding a photo moderation" do
|
35
|
+
photo = Photo.create!(:remote_photo_url => SAMPLE_PHOTO_URL)
|
36
|
+
|
37
|
+
Photo.count.should eq(0)
|
38
|
+
dirEmpty?(tempdir).should be_false
|
39
|
+
Moderation.last.discard
|
40
|
+
dirEmpty?(tempdir).should be_true
|
41
|
+
|
42
|
+
Photo.count.should eq(0)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should put changed photos on existing records to moderation" do
|
46
|
+
photo = Photo.create!
|
47
|
+
|
48
|
+
Photo.count.should eq(0)
|
49
|
+
Moderation.last.accept
|
50
|
+
|
51
|
+
p = Photo.first
|
52
|
+
p.remote_photo_url = SAMPLE_PHOTO_URL
|
53
|
+
dirEmpty?(uploaddir).should be_true
|
54
|
+
p.save
|
55
|
+
dirEmpty?(uploaddir).should be_true
|
56
|
+
|
57
|
+
Photo.first.photo.file.should be_nil
|
58
|
+
Moderation.count.should eq(1)
|
59
|
+
|
60
|
+
dirEmpty?(tempdir).should be_false
|
61
|
+
Moderation.last.accept
|
62
|
+
dirEmpty?(tempdir).should be_true
|
63
|
+
dirEmpty?(uploaddir).should be_false
|
64
|
+
Photo.first.photo.file.should_not be_nil
|
65
|
+
assert(Photo.first.photo.file.file =~ /logo_arnes\.gif/)
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
tempdir = File.expand_path("../../../public/uploads/tmp", __FILE__)
|
4
|
+
uploaddir = "/Users/apple/rails/has_moderated/test/dummy/public/uploads/photo/photo/1"
|
5
|
+
SAMPLE_PHOTO_URL = "http://www.arnes.si/typo3conf/ext/ag_arnes_eff_template/templates/template-index/images/logo_arnes.gif"
|
6
|
+
|
7
|
+
describe TaskPhoto do
|
8
|
+
before(:each) do
|
9
|
+
FileUtils.rm_rf(tempdir) # remove temp dir
|
10
|
+
FileUtils.rm_rf(File.expand_path("../../../public/uploads", __FILE__)) # remove uploads dir
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should moderate photos for task on create even if photos themselves are not moderated" do
|
14
|
+
t = Task.new :title => "Task 1"
|
15
|
+
p = t.task_photos.build
|
16
|
+
p.remote_photo_url = SAMPLE_PHOTO_URL
|
17
|
+
t.save
|
18
|
+
Moderation.count.should eq(1)
|
19
|
+
Task.count.should eq(0)
|
20
|
+
TaskPhoto.count.should eq(0)
|
21
|
+
|
22
|
+
Moderation.last.accept
|
23
|
+
|
24
|
+
Task.count.should eq(1)
|
25
|
+
Task.first.title.should eq("Task 1")
|
26
|
+
p = Task.first.task_photos.first
|
27
|
+
p.should_not be_nil
|
28
|
+
p.photo.should_not be_nil
|
29
|
+
p.photo.file.should_not be_nil
|
30
|
+
end
|
31
|
+
end
|
@@ -113,7 +113,7 @@ describe Task do
|
|
113
113
|
Task.last.desc.should eq("Hollywood Hills")
|
114
114
|
end
|
115
115
|
|
116
|
-
it "remembers associations to existing records" do
|
116
|
+
it "remembers associations to existing records on create" do
|
117
117
|
subtask = Subtask.create! :title => "Bye Bye"
|
118
118
|
Subtask.count.should eq(1)
|
119
119
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: has_moderated
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 11
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 10
|
10
|
+
version: 0.0.10
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jan Berdajs
|
@@ -15,10 +15,11 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-10-04 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
|
+
type: :runtime
|
22
23
|
requirement: &id001 !ruby/object:Gem::Requirement
|
23
24
|
none: false
|
24
25
|
requirements:
|
@@ -33,8 +34,8 @@ dependencies:
|
|
33
34
|
version_requirements: *id001
|
34
35
|
name: rails
|
35
36
|
prerelease: false
|
36
|
-
type: :runtime
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
|
+
type: :development
|
38
39
|
requirement: &id002 !ruby/object:Gem::Requirement
|
39
40
|
none: false
|
40
41
|
requirements:
|
@@ -47,7 +48,6 @@ dependencies:
|
|
47
48
|
version_requirements: *id002
|
48
49
|
name: sqlite3
|
49
50
|
prerelease: false
|
50
|
-
type: :development
|
51
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
52
|
email:
|
53
53
|
- mrbrdo@gmail.com
|
@@ -58,60 +58,73 @@ extensions: []
|
|
58
58
|
extra_rdoc_files: []
|
59
59
|
|
60
60
|
files:
|
61
|
-
- lib/has_moderated.rb
|
62
|
-
- lib/tasks/has_moderated_tasks.rake
|
63
|
-
- lib/has_moderated/version.rb
|
64
61
|
- lib/generators/has_moderated/install/install_generator.rb
|
65
62
|
- lib/generators/has_moderated/install/templates/migration.rb
|
66
63
|
- lib/generators/has_moderated/install/templates/moderation.rb
|
67
64
|
- lib/generators/USAGE
|
65
|
+
- lib/has_moderated/carrier_wave.rb
|
66
|
+
- lib/has_moderated/moderation_model.rb
|
67
|
+
- lib/has_moderated/version.rb
|
68
|
+
- lib/has_moderated.rb
|
69
|
+
- lib/tasks/has_moderated_tasks.rake
|
68
70
|
- MIT-LICENSE
|
69
71
|
- Rakefile
|
70
72
|
- README.rdoc
|
71
|
-
- test/dummy/
|
72
|
-
- test/dummy/
|
73
|
+
- test/dummy/app/assets/javascripts/application.js
|
74
|
+
- test/dummy/app/assets/stylesheets/application.css
|
75
|
+
- test/dummy/app/controllers/application_controller.rb
|
76
|
+
- test/dummy/app/helpers/application_helper.rb
|
77
|
+
- test/dummy/app/models/moderation.rb
|
78
|
+
- test/dummy/app/models/photo.rb
|
79
|
+
- test/dummy/app/models/subtask.rb
|
80
|
+
- test/dummy/app/models/task.rb
|
81
|
+
- test/dummy/app/models/task_all.rb
|
82
|
+
- test/dummy/app/models/task_photo.rb
|
83
|
+
- test/dummy/app/uploaders/generic_uploader.rb
|
84
|
+
- test/dummy/app/views/layouts/application.html.erb
|
85
|
+
- test/dummy/config/application.rb
|
73
86
|
- test/dummy/config/boot.rb
|
87
|
+
- test/dummy/config/database.yml
|
74
88
|
- test/dummy/config/environment.rb
|
75
|
-
- test/dummy/config/
|
76
|
-
- test/dummy/config/
|
77
|
-
- test/dummy/config/
|
89
|
+
- test/dummy/config/environments/development.rb
|
90
|
+
- test/dummy/config/environments/production.rb
|
91
|
+
- test/dummy/config/environments/test.rb
|
78
92
|
- test/dummy/config/initializers/backtrace_silencers.rb
|
79
|
-
- test/dummy/config/initializers/wrap_parameters.rb
|
80
93
|
- test/dummy/config/initializers/inflections.rb
|
94
|
+
- test/dummy/config/initializers/mime_types.rb
|
81
95
|
- test/dummy/config/initializers/secret_token.rb
|
82
|
-
- test/dummy/config/
|
83
|
-
- test/dummy/config/
|
96
|
+
- test/dummy/config/initializers/session_store.rb
|
97
|
+
- test/dummy/config/initializers/wrap_parameters.rb
|
98
|
+
- test/dummy/config/locales/en.yml
|
84
99
|
- test/dummy/config/routes.rb
|
85
|
-
- test/dummy/config
|
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
|
100
|
+
- test/dummy/config.ru
|
90
101
|
- test/dummy/db/development.sqlite3
|
91
|
-
- test/dummy/db/migrate/20110908025410_create_task_alls.rb
|
92
|
-
- test/dummy/db/migrate/20110901013228_create_subtasks.rb
|
93
102
|
- test/dummy/db/migrate/20110901013205_create_tasks.rb
|
94
|
-
- test/dummy/db/migrate/
|
103
|
+
- test/dummy/db/migrate/20110901013228_create_subtasks.rb
|
95
104
|
- test/dummy/db/migrate/20110901013618_create_moderations.rb
|
105
|
+
- test/dummy/db/migrate/20110908025410_create_task_alls.rb
|
106
|
+
- test/dummy/db/migrate/20110908025606_add_task_all_id_to_subtasks.rb
|
107
|
+
- test/dummy/db/migrate/20111003205633_create_photos.rb
|
108
|
+
- test/dummy/db/migrate/20111003234101_create_task_photos.rb
|
109
|
+
- test/dummy/db/schema.rb
|
96
110
|
- test/dummy/db/test.sqlite3
|
97
|
-
- test/dummy/
|
98
|
-
- test/dummy/
|
99
|
-
- test/dummy/
|
100
|
-
- test/dummy/app/models/subtask.rb
|
101
|
-
- test/dummy/app/models/task_all.rb
|
102
|
-
- test/dummy/app/assets/stylesheets/application.css
|
103
|
-
- test/dummy/app/assets/javascripts/application.js
|
104
|
-
- test/dummy/app/controllers/application_controller.rb
|
105
|
-
- test/dummy/app/views/layouts/application.html.erb
|
106
|
-
- test/dummy/spec/models/task_spec.rb
|
107
|
-
- test/dummy/spec/spec_helper.rb
|
108
|
-
- test/dummy/spec/factories/task_alls.rb
|
109
|
-
- test/dummy/config.ru
|
110
|
-
- test/dummy/Rakefile
|
111
|
-
- test/dummy/public/500.html
|
111
|
+
- test/dummy/falaf/test.rb
|
112
|
+
- test/dummy/log/development.log
|
113
|
+
- test/dummy/log/test.log
|
112
114
|
- test/dummy/public/404.html
|
113
|
-
- test/dummy/public/favicon.ico
|
114
115
|
- test/dummy/public/422.html
|
116
|
+
- test/dummy/public/500.html
|
117
|
+
- test/dummy/public/favicon.ico
|
118
|
+
- test/dummy/public/uploads/task_photo/photo/logo_arnes.gif
|
119
|
+
- test/dummy/Rakefile
|
120
|
+
- test/dummy/script/rails
|
121
|
+
- test/dummy/spec/factories/photos.rb
|
122
|
+
- test/dummy/spec/factories/task_alls.rb
|
123
|
+
- test/dummy/spec/factories/task_photos.rb
|
124
|
+
- test/dummy/spec/models/photo_spec.rb
|
125
|
+
- test/dummy/spec/models/task_photo_spec.rb
|
126
|
+
- test/dummy/spec/models/task_spec.rb
|
127
|
+
- test/dummy/spec/spec_helper.rb
|
115
128
|
has_rdoc: true
|
116
129
|
homepage: https://github.com/mrbrdo/has_moderated
|
117
130
|
licenses: []
|
@@ -147,47 +160,58 @@ signing_key:
|
|
147
160
|
specification_version: 3
|
148
161
|
summary: Moderate fields or entire model instances.
|
149
162
|
test_files:
|
150
|
-
- test/dummy/
|
151
|
-
- test/dummy/
|
163
|
+
- test/dummy/app/assets/javascripts/application.js
|
164
|
+
- test/dummy/app/assets/stylesheets/application.css
|
165
|
+
- test/dummy/app/controllers/application_controller.rb
|
166
|
+
- test/dummy/app/helpers/application_helper.rb
|
167
|
+
- test/dummy/app/models/moderation.rb
|
168
|
+
- test/dummy/app/models/photo.rb
|
169
|
+
- test/dummy/app/models/subtask.rb
|
170
|
+
- test/dummy/app/models/task.rb
|
171
|
+
- test/dummy/app/models/task_all.rb
|
172
|
+
- test/dummy/app/models/task_photo.rb
|
173
|
+
- test/dummy/app/uploaders/generic_uploader.rb
|
174
|
+
- test/dummy/app/views/layouts/application.html.erb
|
175
|
+
- test/dummy/config/application.rb
|
152
176
|
- test/dummy/config/boot.rb
|
177
|
+
- test/dummy/config/database.yml
|
153
178
|
- test/dummy/config/environment.rb
|
154
|
-
- test/dummy/config/
|
155
|
-
- test/dummy/config/
|
156
|
-
- test/dummy/config/
|
179
|
+
- test/dummy/config/environments/development.rb
|
180
|
+
- test/dummy/config/environments/production.rb
|
181
|
+
- test/dummy/config/environments/test.rb
|
157
182
|
- test/dummy/config/initializers/backtrace_silencers.rb
|
158
|
-
- test/dummy/config/initializers/wrap_parameters.rb
|
159
183
|
- test/dummy/config/initializers/inflections.rb
|
184
|
+
- test/dummy/config/initializers/mime_types.rb
|
160
185
|
- test/dummy/config/initializers/secret_token.rb
|
161
|
-
- test/dummy/config/
|
162
|
-
- test/dummy/config/
|
186
|
+
- test/dummy/config/initializers/session_store.rb
|
187
|
+
- test/dummy/config/initializers/wrap_parameters.rb
|
188
|
+
- test/dummy/config/locales/en.yml
|
163
189
|
- test/dummy/config/routes.rb
|
164
|
-
- test/dummy/config
|
165
|
-
- test/dummy/config/environments/test.rb
|
166
|
-
- test/dummy/config/environments/development.rb
|
167
|
-
- test/dummy/script/rails
|
168
|
-
- test/dummy/db/schema.rb
|
190
|
+
- test/dummy/config.ru
|
169
191
|
- test/dummy/db/development.sqlite3
|
170
|
-
- test/dummy/db/migrate/20110908025410_create_task_alls.rb
|
171
|
-
- test/dummy/db/migrate/20110901013228_create_subtasks.rb
|
172
192
|
- test/dummy/db/migrate/20110901013205_create_tasks.rb
|
173
|
-
- test/dummy/db/migrate/
|
193
|
+
- test/dummy/db/migrate/20110901013228_create_subtasks.rb
|
174
194
|
- test/dummy/db/migrate/20110901013618_create_moderations.rb
|
195
|
+
- test/dummy/db/migrate/20110908025410_create_task_alls.rb
|
196
|
+
- test/dummy/db/migrate/20110908025606_add_task_all_id_to_subtasks.rb
|
197
|
+
- test/dummy/db/migrate/20111003205633_create_photos.rb
|
198
|
+
- test/dummy/db/migrate/20111003234101_create_task_photos.rb
|
199
|
+
- test/dummy/db/schema.rb
|
175
200
|
- test/dummy/db/test.sqlite3
|
176
|
-
- test/dummy/
|
177
|
-
- test/dummy/
|
178
|
-
- test/dummy/
|
179
|
-
- test/dummy/app/models/subtask.rb
|
180
|
-
- test/dummy/app/models/task_all.rb
|
181
|
-
- test/dummy/app/assets/stylesheets/application.css
|
182
|
-
- test/dummy/app/assets/javascripts/application.js
|
183
|
-
- test/dummy/app/controllers/application_controller.rb
|
184
|
-
- test/dummy/app/views/layouts/application.html.erb
|
185
|
-
- test/dummy/spec/models/task_spec.rb
|
186
|
-
- test/dummy/spec/spec_helper.rb
|
187
|
-
- test/dummy/spec/factories/task_alls.rb
|
188
|
-
- test/dummy/config.ru
|
189
|
-
- test/dummy/Rakefile
|
190
|
-
- test/dummy/public/500.html
|
201
|
+
- test/dummy/falaf/test.rb
|
202
|
+
- test/dummy/log/development.log
|
203
|
+
- test/dummy/log/test.log
|
191
204
|
- test/dummy/public/404.html
|
192
|
-
- test/dummy/public/favicon.ico
|
193
205
|
- test/dummy/public/422.html
|
206
|
+
- test/dummy/public/500.html
|
207
|
+
- test/dummy/public/favicon.ico
|
208
|
+
- test/dummy/public/uploads/task_photo/photo/logo_arnes.gif
|
209
|
+
- test/dummy/Rakefile
|
210
|
+
- test/dummy/script/rails
|
211
|
+
- test/dummy/spec/factories/photos.rb
|
212
|
+
- test/dummy/spec/factories/task_alls.rb
|
213
|
+
- test/dummy/spec/factories/task_photos.rb
|
214
|
+
- test/dummy/spec/models/photo_spec.rb
|
215
|
+
- test/dummy/spec/models/task_photo_spec.rb
|
216
|
+
- test/dummy/spec/models/task_spec.rb
|
217
|
+
- test/dummy/spec/spec_helper.rb
|