file_share 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (161) hide show
  1. data/Gemfile +16 -0
  2. data/Gemfile.lock +147 -0
  3. data/README +0 -0
  4. data/Rakefile +38 -0
  5. data/VERSION +1 -0
  6. data/app/controllers/application_controller.rb +4 -0
  7. data/app/controllers/file_attachments_controller.rb +123 -0
  8. data/app/controllers/file_share/application_controller.rb +5 -0
  9. data/app/helpers/file_attachments_helper.rb +9 -0
  10. data/app/helpers/file_share/application_helper.rb +60 -0
  11. data/app/models/file_attachment.rb +104 -0
  12. data/app/models/file_container.rb +30 -0
  13. data/app/views/file-share-shared/_flash.html.erb +7 -0
  14. data/app/views/file-share-shared/_main_menu.html.erb +3 -0
  15. data/app/views/file-share-shared/_navigation.html.erb +2 -0
  16. data/app/views/file_attachments/_file_attachment.html.erb +17 -0
  17. data/app/views/file_attachments/_file_attachments.html.erb +52 -0
  18. data/app/views/file_attachments/_file_container_option.html.erb +4 -0
  19. data/app/views/file_attachments/_file_container_select.html.erb +14 -0
  20. data/app/views/file_attachments/_plupload_with_listing.html.erb +142 -0
  21. data/app/views/file_attachments/_upload_form.html.erb +22 -0
  22. data/app/views/file_attachments/edit.html.erb +32 -0
  23. data/app/views/file_attachments/index.html.erb +1 -0
  24. data/app/views/file_attachments/update.js.rjs +13 -0
  25. data/app/views/layouts/application.html.erb +56 -0
  26. data/config/application.rb +42 -0
  27. data/config/blueprint_settings.yml +9 -0
  28. data/config/boot.rb +13 -0
  29. data/config/cucumber.yml +8 -0
  30. data/config/database.example.yml +22 -0
  31. data/config/environment.rb +5 -0
  32. data/config/environments/development.rb +26 -0
  33. data/config/environments/production.rb +49 -0
  34. data/config/environments/test.rb +35 -0
  35. data/config/initializers/backtrace_silencers.rb +7 -0
  36. data/config/initializers/inflections.rb +10 -0
  37. data/config/initializers/mime_types.rb +5 -0
  38. data/config/initializers/secret_token.rb +9 -0
  39. data/config/initializers/session_store.rb +10 -0
  40. data/config/locales/en.yml +5 -0
  41. data/config/routes.rb +64 -0
  42. data/db/migrate/20101020002635_create_file_attachments.rb +19 -0
  43. data/db/schema.rb +27 -0
  44. data/db/seeds.rb +7 -0
  45. data/lib/file_share.rb +3 -0
  46. data/lib/file_share/engine.rb +25 -0
  47. data/lib/generators/file_share/install/USAGE +5 -0
  48. data/lib/generators/file_share/install/install_generator.rb +19 -0
  49. data/lib/generators/file_share/install/templates/file_share.rake +169 -0
  50. data/lib/tasks/blueprint.rake +25 -0
  51. data/lib/tasks/cucumber.rake +53 -0
  52. data/public/404.html +26 -0
  53. data/public/422.html +26 -0
  54. data/public/500.html +26 -0
  55. data/public/favicon.ico +0 -0
  56. data/public/images/rails.png +0 -0
  57. data/public/javascripts/file_share.js +62 -0
  58. data/public/javascripts/file_share_behaviors.js +131 -0
  59. data/public/javascripts/idselector.js +538 -0
  60. data/public/javascripts/jquery-1.3.2.min.js +19 -0
  61. data/public/javascripts/jquery-ui-1.7.2.custom.min.js +298 -0
  62. data/public/javascripts/jquery.clonePosition.js +27 -0
  63. data/public/javascripts/jquery.js +154 -0
  64. data/public/javascripts/jquery.qtip-1.0.0-rc3.js +2149 -0
  65. data/public/javascripts/jquery.qtip-1.0.0-rc3.min.js +15 -0
  66. data/public/javascripts/jquery.string.1.0-min.js +6 -0
  67. data/public/javascripts/jquery.tablesorter.min.js +2 -0
  68. data/public/javascripts/lowpro.jquery.js +224 -0
  69. data/public/javascripts/plupload/gears_init.js +86 -0
  70. data/public/javascripts/plupload/jquery.plupload.queue.min.js +202 -0
  71. data/public/javascripts/plupload/plupload.browserplus.min.js +1 -0
  72. data/public/javascripts/plupload/plupload.flash.min.js +1 -0
  73. data/public/javascripts/plupload/plupload.flash.swf +0 -0
  74. data/public/javascripts/plupload/plupload.full.min.js +1 -0
  75. data/public/javascripts/plupload/plupload.gears.min.js +1 -0
  76. data/public/javascripts/plupload/plupload.html4.min.js +1 -0
  77. data/public/javascripts/plupload/plupload.html5.min.js +1 -0
  78. data/public/javascripts/plupload/plupload.min.js +1 -0
  79. data/public/javascripts/plupload/plupload.silverlight.min.js +1 -0
  80. data/public/javascripts/plupload/plupload.silverlight.xap +0 -0
  81. data/public/javascripts/rails.js +132 -0
  82. data/public/robots.txt +5 -0
  83. data/public/stylesheets/blueprint/grid.css +290 -0
  84. data/public/stylesheets/blueprint/icons/cross.png +0 -0
  85. data/public/stylesheets/blueprint/icons/doc.png +0 -0
  86. data/public/stylesheets/blueprint/icons/email.png +0 -0
  87. data/public/stylesheets/blueprint/icons/external.png +0 -0
  88. data/public/stylesheets/blueprint/icons/feed.png +0 -0
  89. data/public/stylesheets/blueprint/icons/im.png +0 -0
  90. data/public/stylesheets/blueprint/icons/key.png +0 -0
  91. data/public/stylesheets/blueprint/icons/pdf.png +0 -0
  92. data/public/stylesheets/blueprint/icons/tick.png +0 -0
  93. data/public/stylesheets/blueprint/icons/visited.png +0 -0
  94. data/public/stylesheets/blueprint/icons/xls.png +0 -0
  95. data/public/stylesheets/blueprint/ie.css +36 -0
  96. data/public/stylesheets/blueprint/oldgrid.css +161 -0
  97. data/public/stylesheets/blueprint/plugins/buttons/icons/cross.png +0 -0
  98. data/public/stylesheets/blueprint/plugins/buttons/icons/key.png +0 -0
  99. data/public/stylesheets/blueprint/plugins/buttons/icons/tick.png +0 -0
  100. data/public/stylesheets/blueprint/plugins/buttons/readme.txt +32 -0
  101. data/public/stylesheets/blueprint/plugins/buttons/screen.css +97 -0
  102. data/public/stylesheets/blueprint/plugins/fancy-type/readme.txt +14 -0
  103. data/public/stylesheets/blueprint/plugins/fancy-type/screen.css +71 -0
  104. data/public/stylesheets/blueprint/plugins/link-icons/icons/doc.png +0 -0
  105. data/public/stylesheets/blueprint/plugins/link-icons/icons/email.png +0 -0
  106. data/public/stylesheets/blueprint/plugins/link-icons/icons/external.png +0 -0
  107. data/public/stylesheets/blueprint/plugins/link-icons/icons/feed.png +0 -0
  108. data/public/stylesheets/blueprint/plugins/link-icons/icons/im.png +0 -0
  109. data/public/stylesheets/blueprint/plugins/link-icons/icons/pdf.png +0 -0
  110. data/public/stylesheets/blueprint/plugins/link-icons/icons/visited.png +0 -0
  111. data/public/stylesheets/blueprint/plugins/link-icons/icons/xls.png +0 -0
  112. data/public/stylesheets/blueprint/plugins/link-icons/readme.txt +18 -0
  113. data/public/stylesheets/blueprint/plugins/link-icons/screen.css +40 -0
  114. data/public/stylesheets/blueprint/plugins/rtl/readme.txt +10 -0
  115. data/public/stylesheets/blueprint/plugins/rtl/screen.css +110 -0
  116. data/public/stylesheets/blueprint/plugins/silksprite/sprite.css +1 -0
  117. data/public/stylesheets/blueprint/plugins/silksprite/sprites.png +0 -0
  118. data/public/stylesheets/blueprint/print.css +29 -0
  119. data/public/stylesheets/blueprint/readme.txt +12 -0
  120. data/public/stylesheets/blueprint/screen.css +402 -0
  121. data/public/stylesheets/error_messages.css +65 -0
  122. data/public/stylesheets/formtastic.css +138 -0
  123. data/public/stylesheets/formtastic_changes.css +33 -0
  124. data/public/stylesheets/main_elements.css +26 -0
  125. data/public/stylesheets/plupload/backgrounds.gif +0 -0
  126. data/public/stylesheets/plupload/buttons-disabled.png +0 -0
  127. data/public/stylesheets/plupload/buttons.png +0 -0
  128. data/public/stylesheets/plupload/delete.gif +0 -0
  129. data/public/stylesheets/plupload/done.gif +0 -0
  130. data/public/stylesheets/plupload/error.gif +0 -0
  131. data/public/stylesheets/plupload/screen.css +172 -0
  132. data/public/stylesheets/plupload/transp50.png +0 -0
  133. data/public/stylesheets/reset.css +60 -0
  134. data/public/stylesheets/scaffold.css +55 -0
  135. data/public/stylesheets/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  136. data/public/stylesheets/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
  137. data/public/stylesheets/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  138. data/public/stylesheets/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  139. data/public/stylesheets/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
  140. data/public/stylesheets/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  141. data/public/stylesheets/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  142. data/public/stylesheets/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  143. data/public/stylesheets/smoothness/images/ui-icons_222222_256x240.png +0 -0
  144. data/public/stylesheets/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
  145. data/public/stylesheets/smoothness/images/ui-icons_454545_256x240.png +0 -0
  146. data/public/stylesheets/smoothness/images/ui-icons_888888_256x240.png +0 -0
  147. data/public/stylesheets/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
  148. data/public/stylesheets/smoothness/jquery-ui-1.7.2.custom.css +406 -0
  149. data/public/stylesheets/tablesorter/blue/asc.gif +0 -0
  150. data/public/stylesheets/tablesorter/blue/bg.gif +0 -0
  151. data/public/stylesheets/tablesorter/blue/desc.gif +0 -0
  152. data/public/stylesheets/tablesorter/blue/style.css +39 -0
  153. data/public/stylesheets/text_and_colors.css +49 -0
  154. data/spec/controllers/file_attachments_controller_spec.rb +305 -0
  155. data/spec/fixtures/file_share_file_attachments.yml +2 -0
  156. data/spec/fixtures/somefile.txt +1 -0
  157. data/spec/helpers/file_attachments_helper_spec.rb +11 -0
  158. data/spec/models/file_attachment_spec.rb +57 -0
  159. data/spec/models/file_container_spec.rb +23 -0
  160. data/spec/spec_helper.rb +27 -0
  161. metadata +474 -0
@@ -0,0 +1,39 @@
1
+ /* tables */
2
+ table.tablesorter {
3
+ font-family:arial;
4
+ background-color: #CDCDCD;
5
+ margin:10px 0pt 15px;
6
+ font-size: 8pt;
7
+ width: 100%;
8
+ text-align: left;
9
+ }
10
+ table.tablesorter thead tr th, table.tablesorter tfoot tr th {
11
+ background-color: #e6EEEE;
12
+ border: 1px solid #FFF;
13
+ font-size: 8pt;
14
+ padding: 4px;
15
+ }
16
+ table.tablesorter thead tr .header {
17
+ background-image: url(bg.gif);
18
+ background-repeat: no-repeat;
19
+ background-position: center right;
20
+ cursor: pointer;
21
+ }
22
+ table.tablesorter tbody td {
23
+ color: #3D3D3D;
24
+ padding: 4px;
25
+ background-color: #FFF;
26
+ vertical-align: top;
27
+ }
28
+ table.tablesorter tbody tr.odd td {
29
+ background-color:#F0F0F6;
30
+ }
31
+ table.tablesorter thead tr .headerSortUp {
32
+ background-image: url(asc.gif);
33
+ }
34
+ table.tablesorter thead tr .headerSortDown {
35
+ background-image: url(desc.gif);
36
+ }
37
+ table.tablesorter thead tr .headerSortDown, table.tablesorter thead tr .headerSortUp {
38
+ background-color: #8dbdd8;
39
+ }
@@ -0,0 +1,49 @@
1
+ /*
2
+ .red { color: red }
3
+ .blue { color: blue }
4
+ .green { color: green }
5
+ .purple { color: #9F009C }
6
+ .gold { color: #FFD700 }
7
+ .yellow { color: #FD3; }
8
+ .brown { color: #630; }
9
+ .white { color: #FFF; }
10
+ .lightbrown { color: #FC9; }
11
+ .lightblue { color: #CCF; }
12
+ .lightgreen { color: #90EE90; }
13
+ .lightred { color: #F66; }
14
+ .lightpurple { color: #9F339C }
15
+ .lightgray { color: #aaa }
16
+ .gray { color: #999 }
17
+ .darkred { color: #900; }
18
+ .darkblue { color: #009; }
19
+ .darkgreen { color: #090; }
20
+ .smalltext { font-size: 11px; }
21
+ .small_text { font-size: 11px; }
22
+ .big_text { font-size: 16px; line-height: 150% }
23
+ .large_text { font-size: 18px; line-height: 150% }
24
+ .huge_text { font-size: 22px; line-height: 150% }
25
+ .tiny_text { font-size: 9px; }
26
+ .pink_background { background: #FDD; }
27
+ .aqua_background { background: #DFF; }
28
+ div.smalltext ul { font-size: 11px; }
29
+
30
+ table.nice_table { background: #660; width: auto; }
31
+ table.nice_table th { background: #CC9; padding: 2px 6px; font-size: 13px;}
32
+ table.nice_table tr { background: #FFF; }
33
+ table.nice_table td { padding: 4px 12px; font-size: 12px; }
34
+
35
+ table.nice_data_table { background: #660; }
36
+ table.nice_data_table th { background: #CC9; padding: 4px 8px; font-size: 13px;}
37
+ table.nice_data_table tr { background: #FFF; }
38
+ table.nice_data_table td { padding: 4px; font-size: 12px; text-align:right; }
39
+
40
+
41
+ table.small_table td { padding: 3px; margin: 1px; font-size: 11px; }
42
+ table.small_table_narrow td { padding: 2px; margin: 0px; font-size: 11px; }
43
+ table.tiny_table td { padding: 0px 2px; margin: 0px 2px; font-size: 9px; }
44
+
45
+ table.tablesorter { width: auto; }
46
+ table.tablesorter tbody td { padding: 4px 12px; }
47
+ table.tablesorter th.header { padding-right: 24px; }
48
+ table.tablesorter thead tr th { font-size: 13px; }
49
+ */
@@ -0,0 +1,305 @@
1
+ require 'spec_helper'
2
+
3
+ describe FileAttachmentsController do
4
+ def flash_now
5
+ controller.instance_eval{flash.stub!(:sweep)}
6
+ end
7
+
8
+ def mock_container
9
+ @mock_container ||= mock_model(FileAttachment)
10
+ end
11
+
12
+ def mock_file_attachment
13
+ @mock_file_attachment ||= mock_model(FileAttachment, {
14
+ :uploaded_file => some_file,
15
+ :filepath= => nil,
16
+ :name => 'what',
17
+ :attachable_id => mock_container.id,
18
+ :attachable_type => mock_container.class,
19
+ :attachable => mock_container,
20
+ :save => true
21
+ })
22
+ end
23
+
24
+ def some_file
25
+ fixture_file_upload(File.join(Rails.root.to_s, 'spec', 'fixtures', 'somefile.txt'), 'text/plain')
26
+ end
27
+
28
+ describe "when logged in as admin" do
29
+ before do
30
+ FileAttachment.stub(:new).and_return(mock_file_attachment)
31
+ @params = {
32
+ :description => "blah blah",
33
+ :name => "agenda",
34
+ :uploaded_file => some_file,
35
+ :container => "MockContainer_#{mock_container.id}"
36
+ }
37
+ end
38
+
39
+ context "http upload" do
40
+ context "no file is selected for upload" do
41
+ it "redirects to the home page if no file was uploaded" do
42
+ post :create, :file_attachment => {}
43
+ response.should redirect_to(file_attachments_path(:std => 1))
44
+ end
45
+ it "sets a flash[:warning]" do
46
+ post :create, :file_attachment => {}
47
+ flash[:warning].should_not be_nil
48
+ end
49
+ end
50
+ it "should upload a new file attachment with an attachable" do
51
+ FileAttachment.should_receive(:new).and_return(mock_file_attachment)
52
+ post :create, :file_attachment => @params
53
+ response.should redirect_to(file_attachment_path(mock_container, {:std => 1}))
54
+ end
55
+ it "should upload a new file attachment without an attachable" do
56
+ @params.merge!(:container => '')
57
+ mock_file = mock_model(FileAttachment, @params.merge({
58
+ :save => nil,
59
+ :errors => mock('Error', {
60
+ :full_messages => []
61
+ }),
62
+ :attachable_id => '',
63
+ :attachable_type => '',
64
+ :attachable => nil
65
+ }))
66
+ FileAttachment.should_receive(:new).and_return(mock_file)
67
+ post :create, :file_attachment => @params
68
+ end
69
+ it "should save the new file attachment" do
70
+ mock_file_attachment.should_receive(:save)
71
+ post :create, :file_attachment => @params
72
+ end
73
+ it "when file is attached to an attachable, redirect to the attachable page" do
74
+ post :create, :file_attachment => @params
75
+ response.should redirect_to file_attachment_path(mock_container, :std => 1)
76
+ end
77
+ it "when file is not attached, redirect to the file attachments page" do
78
+ mock_file = mock_model(FileAttachment, {
79
+ :uploaded_file => some_file,
80
+ :filepath => nil,
81
+ :name => 'what',
82
+ :save => true,
83
+ :attachable_id => '',
84
+ :attachable_type => '',
85
+ :attachable => nil
86
+ })
87
+ FileAttachment.stub(:new).and_return(mock_file)
88
+ post :create, :file_attachment => @params
89
+ response.should redirect_to file_attachments_path(:std => 1)
90
+ end
91
+ end
92
+
93
+ context "plupload" do
94
+
95
+ before(:each) do
96
+ @params.delete(:name) && @params.delete(:description)
97
+ end
98
+
99
+ it "should upload a new file attachment with an attachable" do
100
+ FileAttachment.should_receive(:new).and_return(mock_file_attachment)
101
+
102
+ post :create, {
103
+ :file => some_file,
104
+ :attachable_type => 'MockContainer',
105
+ :attachable_id => mock_container.id
106
+ }
107
+
108
+ assigns[:file_attachment].should == mock_file_attachment
109
+
110
+ response.should render_template('file_attachments/_file_attachment')
111
+ end
112
+
113
+ it "should upload a new file attachment without an event" do
114
+ post :create, {
115
+ :file => some_file
116
+ }
117
+
118
+ assigns[:file_attachment].should == mock_file_attachment
119
+ end
120
+ end
121
+
122
+ context "delete a file" do
123
+
124
+ before(:each) do
125
+ FileAttachment.stub(:find).and_return(mock_file_attachment)
126
+ mock_file_attachment.stub(:full_path).and_return(File.join(Rails.root.to_s, 'spec', 'fixtures', 'somefile.txt'))
127
+ mock_file_attachment.stub(:destroy).and_return(mock_file_attachment)
128
+ File.stub(:rm)
129
+ end
130
+
131
+ it "load the file attachment" do
132
+ FileAttachment.should_receive(:find).and_return(mock_file_attachment)
133
+ post :destroy, :id => 1
134
+ assigns[:file_attachment].should == mock_file_attachment
135
+ end
136
+
137
+ it "destroys the file attachment" do
138
+ mock_file_attachment.should_receive(:destroy)
139
+ post :destroy, :id => 1
140
+ end
141
+
142
+ it "sets a flash[:notice]" do
143
+ post :destroy, :id => 1
144
+ flash[:notice].should_not be_nil
145
+ end
146
+
147
+ end
148
+
149
+ end
150
+
151
+ describe "when Errno::ENOENT is raised" do
152
+
153
+ before(:each) do
154
+ FileAttachment.stub(:find).and_return(mock_file_attachment)
155
+ mock_file_attachment.stub(:destroy).and_raise(Errno::ENOENT.new("File not found"))
156
+ end
157
+
158
+ it "logs the error" do
159
+ controller.logger.should_receive(:error).with("FileAttachmentsController[destroy] was rescued with :file_not_found. No such file or directory - File not found")
160
+ post :destroy, :id => 1
161
+ end
162
+
163
+ it "sets a flash[:warning]" do
164
+ post :destroy, :id => 1
165
+ flash[:warning].should_not be_nil
166
+ end
167
+
168
+ end
169
+
170
+ describe ":edit, :id => integer" do
171
+
172
+ before(:each) do
173
+ FileAttachment.stub(:find).and_return(mock_file_attachment)
174
+ end
175
+
176
+ it "loads a file_attachment as @file_attachment" do
177
+ FileAttachment.should_receive(:find).with('1').and_return(mock_file_attachment)
178
+ get :edit, :id => "1"
179
+ assigns[:file_attachment].should == @mock_file_attachment
180
+ end
181
+
182
+ it "loads potential containers as @file_containers" do
183
+ FileContainer.stub(:types).and_return([mock_container.class])
184
+ mock_container.class.should_receive(:all).and_return([mock_container])
185
+ get :edit, :id => "1"
186
+ assigns[:file_containers].should eql [mock_container]
187
+ end
188
+
189
+ end
190
+
191
+ describe ":update, :id => integer, :file_attachment => {}" do
192
+
193
+ before(:each) do
194
+ FileAttachment.stub(:find).and_return(mock_file_attachment)
195
+ mock_file_attachment.stub(:update_attributes).and_return(nil)
196
+ end
197
+
198
+ it "loads a file attachment" do
199
+ FileAttachment.should_receive(:find).with('1').and_return(@mock_file_attachment)
200
+ put :update, :id => "1"
201
+ assigns[:file_attachment].should == @mock_file_attachment
202
+ end
203
+
204
+ it "updates the file attachment" do
205
+ @mock_file_attachment.should_receive(:update_attributes).with({
206
+ 'description' => 'some lovely new description',
207
+ 'name' => 'slightly.modified.txt'
208
+ }).and_return(nil)
209
+ put :update, :id => 1, :file_attachment => {
210
+ :description => 'some lovely new description',
211
+ :name => 'slightly.modified.txt'
212
+ }
213
+ end
214
+
215
+ context "update succeeds (std HTML POST:)" do
216
+
217
+ before(:each) do
218
+ @mock_file_attachment.stub(:update_attributes).and_return(true)
219
+ end
220
+
221
+ it "sets a flash[:notice]" do
222
+ put :update, :id => "1"
223
+ flash[:notice].should_not be_nil
224
+ end
225
+
226
+ it "redirects to index or event for file" do
227
+ put :update, :id => "1"
228
+ response.should redirect_to(file_attachment_path(mock_container))
229
+ end
230
+
231
+ end
232
+
233
+ context "update fails (std HTML POST):" do
234
+
235
+ before(:each) do
236
+ flash_now
237
+ @mock_file_attachment.stub(:update_attributes).and_return(false)
238
+ end
239
+
240
+ it "sets a flash[:warning]" do
241
+ put :update, :id => "1"
242
+ flash[:warning].should_not be_nil
243
+ end
244
+
245
+ it "renders the edit template" do
246
+ put :update, :id => "1"
247
+ response.should render_template('file_attachments/edit')
248
+ end
249
+
250
+ end
251
+
252
+ context "xhr POST" do
253
+ it "renders the update template" do
254
+ xhr :put, :update, :id => "1"
255
+ response.should render_template("file_attachments/update")
256
+ end
257
+ end
258
+
259
+ end
260
+
261
+ describe ":download, :id => required" do
262
+ before(:each) do
263
+ mock_file_attachment.stub(:full_path).and_return(File.join(Rails.root.to_s, 'spec', 'fixtures', 'somefile.txt'))
264
+ FileAttachment.stub(:find).and_return(mock_file_attachment)
265
+ end
266
+ it ":download, :id => required" do
267
+ controller.stub(:render)
268
+ controller.should_receive(:send_data).with(
269
+ File.new(File.join(Rails.root.to_s, 'spec', 'fixtures', 'somefile.txt')).read,
270
+ :filename => 'somefile.txt',
271
+ :stream => true,
272
+ :buffer_size => 1.megabyte
273
+ )
274
+ get :download, :id => mock_file_attachment.id
275
+ end
276
+ end
277
+
278
+ describe ":index" do
279
+ before(:each) do
280
+ FileAttachment.stub(:all).and_return([mock_file_attachment])
281
+ mock_container.class.stub(:all).and_return([mock_container])
282
+ end
283
+ it "loads orphaned file attachments as @orphans" do
284
+ FileAttachment.should_receive(:orphans).and_return([mock_file_attachment])
285
+ get :index
286
+ assigns[:orphans].should eql [mock_file_attachment]
287
+ end
288
+ it "loads attached file attachments as @files" do
289
+ FileAttachment.should_receive(:attached).and_return([mock_file_attachment])
290
+ get :index
291
+ assigns[:files].should eql [mock_file_attachment]
292
+ end
293
+ it "loads potential containers as @file_containers" do
294
+ FileContainer.stub(:types).and_return([mock_container.class])
295
+ mock_container.class.should_receive(:all).and_return([mock_container])
296
+ get :index
297
+ assigns[:file_containers].should eql [mock_container]
298
+ end
299
+ it "renders the index template" do
300
+ get :index
301
+ response.should render_template("file_attachments/index")
302
+ end
303
+ end
304
+
305
+ end
@@ -0,0 +1,2 @@
1
+ # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
2
+
@@ -0,0 +1 @@
1
+ fixture file
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe FileAttachmentsHelper do
4
+
5
+ #Delete this example and add some real ones or delete this file
6
+ it "should be included in the object returned by #helper" do
7
+ included_modules = (class << helper; self; end).send :included_modules
8
+ included_modules.should include(FileAttachmentsHelper)
9
+ end
10
+
11
+ end
@@ -0,0 +1,57 @@
1
+ require 'spec_helper'
2
+
3
+ describe FileAttachment do
4
+
5
+ include ActionDispatch::TestProcess # for fixture_file_upload
6
+
7
+ before(:each) do
8
+ @path = File.join(Rails.root.to_s, 'public', 'files')
9
+ @full_path = File.join(@path, 'somefile.txt')
10
+ @trash_path = File.join(@path, 'trash', 'somefile.txt')
11
+
12
+ raise "Please back up and clean out public/files before running this spec" if File.exists?(@full_path) || File.exists?(File.join(@path, 'somefile-1.txt'))
13
+
14
+ @file_attachment = FileAttachment.create!({
15
+ :description => 'unique description',
16
+ :uploaded_file => fixture_file_upload(File.join(Rails.root.to_s, 'spec', 'fixtures', 'somefile.txt'), 'text/plain')
17
+ })
18
+ end
19
+
20
+ after(:each) do
21
+ if File.exists?(@full_path)
22
+ File.delete(@full_path)
23
+ end
24
+ if File.exists?(@trash_path)
25
+ File.delete(@trash_path)
26
+ end
27
+ end
28
+
29
+ it "should generate a unique name" do
30
+ FileUtils.mkdir_p @path
31
+
32
+ new_file = FileAttachment.create!({
33
+ :description => 'other description',
34
+ :uploaded_file => fixture_file_upload(File.join(Rails.root.to_s, 'spec', 'fixtures', 'somefile.txt'), 'text/plain')
35
+ })
36
+
37
+ new_file.filepath.should_not == 'files/somefile.txt'
38
+ new_file.filepath.should == 'files/somefile-1.txt'
39
+ File.exists?(@full_path).should be_true
40
+
41
+ File.delete(File.join(@path, 'somefile-1.txt'))
42
+ end
43
+
44
+ it "should know whether its file actually exists" do
45
+ @file_attachment.file_saved?.should be_true
46
+ File.exists?(@full_path).should be_true
47
+ File.delete(@full_path)
48
+ @file_attachment.file_saved?.should be_false
49
+ end
50
+
51
+ it "should move its file to the trash when destroyed" do
52
+ File.exists?(@full_path).should be_true
53
+ @file_attachment.destroy
54
+ File.exists?(@full_path).should be_false
55
+ File.exists?(@trash_path).should be_true
56
+ end
57
+ end