has_moderated 1.1.4 → 1.1.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -11,7 +11,7 @@ describe Photo do
11
11
  FileUtils.rm_rf(TEMPDIR) # remove temp dir
12
12
  FileUtils.rm_rf(File.expand_path("../../../public/uploads", __FILE__)) # remove uploads dir
13
13
  end
14
-
14
+
15
15
  context "create moderated:" do
16
16
  before do
17
17
  reload_models.photo {
@@ -21,7 +21,7 @@ describe Photo do
21
21
  has_moderated_carrierwave_field :avatar
22
22
  }
23
23
  end
24
-
24
+
25
25
  it "should upload photo" do
26
26
  photo = Photo.create!(:avatar => carrierwave_test_photo)
27
27
 
@@ -36,6 +36,17 @@ describe Photo do
36
36
  photo = Photo.first
37
37
  assert_photo_uploaded(photo.avatar)
38
38
  end
39
+
40
+ it "should not move temp file when doing preview" do
41
+ photo = Photo.create!(:avatar => carrierwave_test_photo)
42
+
43
+ Photo.count.should eq(0)
44
+ tmpEmpty?.should be_false
45
+ uploadEmpty?.should be_true
46
+ Moderation.last.preview
47
+ tmpEmpty?.should be_false
48
+ uploadEmpty?.should be_true
49
+ end
39
50
  end
40
51
 
41
52
  context "not moderated:" do
@@ -44,7 +55,7 @@ describe Photo do
44
55
  mount_uploader :avatar, GenericUploader
45
56
  }
46
57
  end
47
-
58
+
48
59
  it "should upload photo" do
49
60
  photo = Photo.create!(:avatar => carrierwave_test_photo)
50
61
 
@@ -56,7 +67,7 @@ describe Photo do
56
67
  assert_photo_uploaded(photo.avatar)
57
68
  end
58
69
  end
59
-
70
+
60
71
  context "update moderated:" do
61
72
  before do
62
73
  reload_models.photo {
@@ -70,11 +81,11 @@ describe Photo do
70
81
  it "should moderate photo (on create)" do
71
82
  photo = Photo.create! :avatar => carrierwave_test_photo
72
83
  Photo.count.should eq(1)
73
-
84
+
74
85
  Photo.first.avatar.file.should be_nil
75
86
  tmpEmpty?.should be_false
76
87
  uploadEmpty?.should be_true
77
-
88
+
78
89
  Moderation.last.accept
79
90
  tmpEmpty?.should be_true
80
91
  uploadEmpty?.should be_false
@@ -83,11 +94,11 @@ describe Photo do
83
94
  photo = Photo.first
84
95
  assert_photo_uploaded(photo.avatar)
85
96
  end
86
-
97
+
87
98
  it "should moderate photo (on update)" do
88
99
  photo = Photo.create!
89
100
  Photo.count.should eq(1)
90
-
101
+
91
102
  Photo.first.update_attributes :avatar => carrierwave_test_photo
92
103
  tmpEmpty?.should be_false
93
104
  uploadEmpty?.should be_true
@@ -99,7 +110,7 @@ describe Photo do
99
110
  photo = Photo.first
100
111
  assert_photo_uploaded(photo.avatar)
101
112
  end
102
-
113
+
103
114
  it "should delete temporary files if moderation is discarded" do
104
115
  photo = Photo.create! :avatar => carrierwave_test_photo
105
116
  tmpEmpty?.should be_false
@@ -108,8 +119,17 @@ describe Photo do
108
119
  tmpEmpty?.should be_true
109
120
  uploadEmpty?.should be_true
110
121
  end
122
+
123
+ it "should not move temp file when doing preview" do
124
+ photo = Photo.create! :avatar => carrierwave_test_photo
125
+ tmpEmpty?.should be_false
126
+ uploadEmpty?.should be_true
127
+ Moderation.last.preview
128
+ tmpEmpty?.should be_false
129
+ uploadEmpty?.should be_true
130
+ end
111
131
  end
112
-
132
+
113
133
  context "moderated as association to has_moderated_create:" do
114
134
  before do
115
135
  reload_models.task {
@@ -124,9 +144,9 @@ describe Photo do
124
144
  has_moderated_carrierwave_field :avatar
125
145
  belongs_to :task, :class_name => task_class_name, :foreign_key => "parentable_id"
126
146
  }
127
-
147
+
128
148
  end
129
-
149
+
130
150
  it "should upload photo" do
131
151
  task = Task.new :title => "Task 1"
132
152
  task.photos.build :avatar => carrierwave_test_photo
@@ -144,12 +164,12 @@ describe Photo do
144
164
  photo = Task.first.photos.first
145
165
  assert_photo_uploaded(photo.avatar)
146
166
  end
147
-
167
+
148
168
  it "should not add any photos if none were added" do
149
169
  task = Task.new :title => "Task 1"
150
170
  task.renamed_subtasks.build :title => "Subtask 1"
151
171
  task.save
152
-
172
+
153
173
  Moderation.last.parsed_data[:create][:associations][:photos].should be_nil
154
174
 
155
175
  Task.count.should eq(0)
@@ -159,5 +179,41 @@ describe Photo do
159
179
  Task.first.photos.count.should eq(0)
160
180
  Photo.count.should eq(0)
161
181
  end
182
+
183
+ it "should not move temp file when doing preview" do
184
+ task = Task.new :title => "Task 1"
185
+ task.photos.build :avatar => carrierwave_test_photo
186
+ task.save
187
+
188
+ tmpEmpty?.should be_false
189
+ uploadEmpty?.should be_true
190
+ Moderation.last.preview
191
+ tmpEmpty?.should be_false
192
+ uploadEmpty?.should be_true
193
+ end
194
+ end
195
+
196
+ context "moderation preview" do
197
+ it "should show the temporary file as the photo" do
198
+ reload_models.photo {
199
+ mount_uploader :avatar, GenericUploader
200
+ send :include, HasModerated::CarrierWave
201
+ has_moderated_carrierwave_field :avatar
202
+ has_moderated :avatar
203
+ }
204
+
205
+ photo_file = carrierwave_test_photo
206
+ photo = Photo.create! :avatar => photo_file
207
+ tmpEmpty?.should be_false
208
+ uploadEmpty?.should be_true
209
+ preview = Moderation.last.preview
210
+ preview.avatar.url.should match(/\A\/uploads\/tmp\/.+\/test.jpg\z/)
211
+ preview.avatar.current_path.should eq(Moderation.last.parsed_data[:attributes]["avatar_tmp_file"])
212
+ preview.avatar_url.should eq(preview.avatar.url)
213
+ preview.avatar.frozen?.should be_true
214
+
215
+ Photo.last.avatar.current_path.should be_blank
216
+ Photo.last.avatar_url.should be_blank
217
+ end
162
218
  end
163
219
  end
@@ -566,6 +566,12 @@ describe Task do
566
566
  Moderation.last.accept
567
567
  Task.count.should eq(0)
568
568
  end
569
+
570
+ it "returns nil for #preview" do
571
+ Task.create! :title => "Task 1"
572
+ Task.first.destroy
573
+ Moderation.last.preview.should be_nil
574
+ end
569
575
  end
570
576
 
571
577
  #
@@ -652,7 +658,7 @@ describe Task do
652
658
  it "calls moderation callbacks on destroy" do
653
659
  reload_models.task {
654
660
  has_moderated_create
655
- def self.moderatable_discard(m)
661
+ def self.moderatable_discard(m, opts)
656
662
  raise "moderatable_discard"
657
663
  end
658
664
  }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: has_moderated
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.4
4
+ version: 1.1.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-23 00:00:00.000000000 Z
12
+ date: 2012-10-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -241,6 +241,8 @@ files:
241
241
  - test/dummy/public/500.html
242
242
  - test/dummy/public/favicon.ico
243
243
  - test/dummy/public/test.jpg
244
+ - test/dummy/public/uploads/tmp/20121024-1607-1557-8676/test.jpg
245
+ - test/dummy/public/uploads/tmp/20121024-1607-1557-8676/thumb_test.jpg
244
246
  - test/dummy/Rakefile
245
247
  - test/dummy/script/rails
246
248
  - test/dummy/spec/models/photo_spec.rb
@@ -262,7 +264,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
262
264
  version: '0'
263
265
  segments:
264
266
  - 0
265
- hash: -1102405584291945894
267
+ hash: -2367943572117376893
266
268
  required_rubygems_version: !ruby/object:Gem::Requirement
267
269
  none: false
268
270
  requirements:
@@ -271,7 +273,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
271
273
  version: '0'
272
274
  segments:
273
275
  - 0
274
- hash: -1102405584291945894
276
+ hash: -2367943572117376893
275
277
  requirements: []
276
278
  rubyforge_project:
277
279
  rubygems_version: 1.8.24
@@ -314,6 +316,8 @@ test_files:
314
316
  - test/dummy/public/500.html
315
317
  - test/dummy/public/favicon.ico
316
318
  - test/dummy/public/test.jpg
319
+ - test/dummy/public/uploads/tmp/20121024-1607-1557-8676/test.jpg
320
+ - test/dummy/public/uploads/tmp/20121024-1607-1557-8676/thumb_test.jpg
317
321
  - test/dummy/Rakefile
318
322
  - test/dummy/script/rails
319
323
  - test/dummy/spec/models/photo_spec.rb