public
Fork of halorgium/mephisto
Description: A refactored Mephisto that has multiple spam detection engines.
Homepage: http://mephistoblog.com/
Clone URL: git://github.com/francois/mephisto.git
Initial article/asset assignment support.  Perfect for podcasting.

git-svn-id: http://svn.techno-weenie.net/projects/mephisto/trunk@2684 
567b1171-46fb-0310-a4c9-b4bef9110e78
technoweenie (author)
Sun Jan 14 23:34:08 -0800 2007
commit  ecc989e1d5b94895baed0772aa011657f8b02298
tree    c27e09260d2ad28f788752f1594febfc8d8aa795
parent  45893b3ad2bc5f28efcfe4777d80a53a6ecf4ed5
...
1
2
 
 
3
4
5
...
1
2
3
4
5
6
7
0
@@ -1,5 +1,7 @@
0
 * SVN *
0
 
0
+* Initial article/asset assignment support. Perfect for podcasting.
0
+
0
 * Raise MissingThemesError if Site#theme is nil
0
 
0
 * RIP: Site#search_layout
...
9
10
11
12
 
13
14
15
...
117
118
119
 
 
 
 
 
 
 
 
 
 
 
 
 
 
120
121
122
...
9
10
11
 
12
13
14
15
...
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
0
@@ -9,7 +9,7 @@ class Admin::ArticlesController < Admin::BaseController
0
   before_filter :convert_times_to_utc, :only => [:create, :update, :upload]
0
   before_filter :check_for_new_draft, :only => [:create, :update, :upload]
0
   
0
- before_filter :find_site_article, :only => [:edit, :update, :comments, :approve, :unapprove, :destroy]
0
+ before_filter :find_site_article, :only => [:edit, :update, :comments, :approve, :unapprove, :destroy, :attach, :detach]
0
   before_filter :login_required, :except => :upload
0
   before_filter :load_sections, :only => [:new, :edit]
0
 
0
@@ -117,6 +117,20 @@ class Admin::ArticlesController < Admin::BaseController
0
     end
0
   end
0
 
0
+ def attach
0
+ @asset = site.assets.find(params[:version])
0
+ @article.assets.add @asset
0
+ end
0
+
0
+ def detach
0
+ @asset = site.assets.find(params[:version])
0
+ @article.assets.remove @asset
0
+ end
0
+
0
+ def label
0
+ AssignedAsset.update_all ['label = ?', params[:label]], ['article_id = ? and asset_id = ?', params[:id], params[:version]]
0
+ end
0
+
0
   protected
0
     def load_sections
0
       @assets = site.assets.find(:all, :order => 'created_at desc', :limit => 6)
...
16
17
18
19
 
 
20
21
22
...
26
27
28
29
 
30
31
 
32
33
34
...
16
17
18
 
19
20
21
22
23
...
27
28
29
 
30
31
 
32
33
34
35
0
@@ -16,7 +16,8 @@ class ApplicationController < ActionController::Base
0
   
0
     # so not the best place for this...
0
     def asset_image_args_for(asset, thumbnail = :tiny, options = {})
0
- options = options.reverse_merge(:title => "#{asset.title} \n #{asset.tags.join(', ')}")
0
+ thumb_size = Array.new(2).fill(Asset.attachment_options[:thumbnails][thumbnail].to_i).join('x')
0
+ options = options.reverse_merge(:title => "#{asset.title} \n #{asset.tags.join(', ')}", :size => thumb_size)
0
       if asset.movie?
0
         ['/images/mephisto/icons/video.png', options]
0
       elsif asset.audio?
0
@@ -26,9 +27,9 @@ class ApplicationController < ActionController::Base
0
       elsif asset.other?
0
         ['/images/mephisto/icons/doc.png', options]
0
       elsif asset.thumbnails_count.zero?
0
- [asset.public_filename, options.update(:size => Array.new(2).fill(Asset.attachment_options[:thumbnails][thumbnail].to_i).join('x'))]
0
+ [asset.public_filename, options]
0
       else
0
- [asset.public_filename(thumbnail), options]
0
+ [asset.public_filename(thumbnail), options.merge(:size => asset.image_size)]
0
       end
0
     end
0
     helper_method :asset_image_args_for
...
53
54
55
 
 
 
 
56
57
58
...
53
54
55
56
57
58
59
60
61
62
0
@@ -53,6 +53,10 @@ class ArticleDrop < BaseDrop
0
   def changes_feed_url
0
     @changes_feed_url ||= url + '/changes.xml'
0
   end
0
+
0
+ def assets
0
+ @assets ||= liquify(*@source.assets)
0
+ end
0
 
0
   protected
0
     def body_for_mode(mode)
...
32
33
34
 
 
 
 
35
36
37
...
32
33
34
35
36
37
38
39
40
41
0
@@ -32,6 +32,10 @@ module DropFilters
0
   def latest_comments(site, limit = nil)
0
     site.latest_comments(limit || site['articles_per_page'])
0
   end
0
+
0
+ def find_asset(article, label)
0
+ article.assets.detect { |a| a.source.label == label }
0
+ end
0
 
0
   def monthly_articles(section, date = nil)
0
     date = parse_date(date)
...
52
53
54
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
56
57
...
139
140
141
 
 
 
 
142
143
144
...
161
162
163
 
 
 
 
 
 
164
165
...
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
...
154
155
156
157
158
159
160
161
162
163
...
180
181
182
183
184
185
186
187
188
189
190
0
@@ -52,6 +52,21 @@ class Article < Content
0
     end
0
     comment.has_many :all_comments
0
   end
0
+
0
+ has_many :assigned_assets, :order => 'position', :dependent => :destroy
0
+ has_many :assets, :through => :assigned_assets, :conditions => ['assigned_assets.active = ?', true], :select => 'assets.*, assigned_assets.label' do
0
+ def add(asset, label = nil)
0
+ returning AssignedAsset.find_or_create_by_article_id_and_asset_id(proxy_owner.id, asset.id) do |aa|
0
+ aa.label = label
0
+ aa.active = true
0
+ aa.save!
0
+ end
0
+ end
0
+
0
+ def remove(asset)
0
+ AssignedAsset.update_all ['active = ?', false], ['article_id = ? AND asset_id = ?', proxy_owner.id, asset.id]
0
+ end
0
+ end
0
 
0
   class << self
0
     def with_published(&block)
0
@@ -139,6 +154,10 @@ class Article < Content
0
     set_default_filter_from user
0
   end
0
 
0
+ def add_xml(builder)
0
+ add_podcast_xml(builder)
0
+ end
0
+
0
   protected
0
     def convert_to_utc
0
       self.published_at = published_at.utc if published_at
0
@@ -161,4 +180,10 @@ class Article < Content
0
     def reset_comment_attributes
0
       Content.update_all ['title = ?, published_at = ?, permalink = ?', title, published_at, permalink], ['article_id = ?', id]
0
     end
0
+
0
+ def add_podcast_xml(builder)
0
+ if asset = assets.find(:first, :conditions => ['label = ?', 'podcast'], :select => 'assets.*, assigned_assets.label')
0
+ builder.link :rel => :enclosure, :type => asset.content_type, :length => asset.size, :href => asset.public_filename
0
+ end
0
+ end
0
 end
0
\ No newline at end of file
...
45
46
47
 
48
49
50
...
45
46
47
48
49
50
51
0
@@ -45,6 +45,7 @@ class Asset < ActiveRecord::Base
0
   include Mephisto::TaggableMethods
0
 
0
   belongs_to :site
0
+ has_many :assigned_assets, :order => 'position', :dependent => :destroy
0
   has_attachment :storage => :file_system, :thumbnails => { :thumb => '120>', :tiny => '50>' }, :max_size => 30.megabytes,
0
     :processor => (Object.const_defined?(:ASSET_IMAGE_PROCESSOR) ? ASSET_IMAGE_PROCESSOR : nil)
0
   before_validation_on_create :set_site_from_parent
...
1
2
3
4
 
5
6
7
8
9
10
11
 
12
13
14
...
1
2
3
 
4
5
6
7
8
9
10
 
11
12
13
14
0
@@ -1,14 +1,14 @@
0
 class AssignedSection < ActiveRecord::Base
0
   belongs_to :article
0
   belongs_to :section, :counter_cache => 'articles_count'
0
- acts_as_list :scope => 'section_id = #{section_id}'
0
+ acts_as_list :scope => :section_id
0
   validates_presence_of :article_id, :section_id
0
   validate_on_create :check_for_dupe_article_and_section
0
 
0
   protected
0
     def check_for_dupe_article_and_section
0
       unless self.class.count(:all, :conditions => ['article_id = ? and section_id = ?', article_id, section_id]).zero?
0
- errors.add_to_base("Cannot have a duplicate categorization for this article and section")
0
+ errors.add_to_base("Cannot have a duplicate assignment for this article and section")
0
       end
0
     end
0
 end
...
14
15
16
 
17
18
19
...
21
22
23
24
25
 
 
 
 
 
 
 
26
27
28
...
32
33
34
35
 
36
37
38
...
42
43
44
45
 
46
47
48
...
14
15
16
17
18
19
20
...
22
23
24
 
 
25
26
27
28
29
30
31
32
33
34
...
38
39
40
 
41
42
43
44
...
48
49
50
 
51
52
53
54
0
@@ -14,6 +14,7 @@
0
 <div class="sgroup" id="filetabs">
0
   <ul class="stabs">
0
     <li id="tab-latest"><a href="#latest-files" class="selected" title="Latest files uploaded">Latest</a></li>
0
+ <li id="tab-attached"><a href="#attached-files" title="Attached Assets">Attached</a></li>
0
     <li id="tab-search"><a href="#search-files" title="Search for files">Search</a></li>
0
     <li id="tab-files"><a href="#upload-files" title="Upload new files">Upload</a></li>
0
     <li id="tab-bucket"><a href="#bucket" title="Upload new files">Bucket</a></li>
0
@@ -21,8 +22,13 @@
0
   
0
   <div id="tabpanels">
0
     <div class="tabpanel" id="latest-files">
0
- <ul id="latest-assets">
0
- <%= render :partial => "admin/assets/widget", :collection => @assets %>
0
+ <ul id="latest-assets" class="asset-list">
0
+ <%= render :partial => "admin/assets/widget", :collection => @assets, :locals => { :prefix => 'latest' } %>
0
+ </ul>
0
+ </div>
0
+ <div class="tabpanel" id="attached-files" style="display:none;">
0
+ <ul id="attached-assets" class="asset-list">
0
+ <%= render :partial => "admin/assets/widget", :collection => @article.assets, :locals => { :prefix => 'attached' } %>
0
       </ul>
0
     </div>
0
     <div class="tabpanel" id="search-files" style="display:none;">
0
@@ -32,7 +38,7 @@
0
       </label>
0
       <input class="searchbox" type="text" size="30" name="q" id="search-files-q" />
0
       <input type="button" value="Search" onclick="TinyTab.callbacks['search-files']($F('search-files-q'))" />
0
- <ul id="search-assets"></ul>
0
+ <ul id="search-assets" class="asset-list"></ul>
0
     </div>
0
     <div class="tabpanel" id="upload-files" style="display:none;">
0
       <p>
0
@@ -42,7 +48,7 @@
0
       <p><strong>2.</strong> <input type="button" value="Upload" onclick="Asset.upload('article-form');" /></p>
0
     </div>
0
     <div class="tabpanel" id="bucket" style="display:none;">
0
- <ul id="bucket-assets">
0
+ <ul id="bucket-assets" class="asset-list">
0
         <% session[:bucket].each do |filename, values| -%>
0
         <li>
0
           <%= link_to(image_tag(*values), filename, :target => '_blank') %>
...
1
 
 
 
 
 
 
 
 
 
 
2
 
 
 
 
 
3
4
...
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
0
@@ -1,3 +1,17 @@
0
-<li id="<%= widget.dom_id(:widget) %>">
0
+<li id="<%= widget.dom_id("#{prefix}-widget") %>" class="widget<%= ' selected-widget' if @article && @article.assets.include?(widget) %>">
0
+<% if prefix == 'attached' -%>
0
+ <div>
0
+ <%= link_to asset_image_for(widget), widget.public_filename %>
0
+ <span>
0
+ <%= text_field_tag :version, (widget.respond_to?(:label) ? widget.label : nil), :id => widget.dom_id("#{prefix}-widget-version"), :class => 'txt' %>
0
+ <a href="#" class="label-widget" id="<%= widget.dom_id("label-#{prefix}-widget") %>">Save</a>
0
+ </span>
0
+ </div>
0
+<% else -%>
0
   <%= link_to asset_image_for(widget), widget.public_filename %>
0
+<% end -%>
0
+ <a href="#"><%= image_tag('mephisto/icons/8-em-cross.png', :size => '16x16', :id => widget.dom_id("detach-#{prefix}-widget"),
0
+ :style => 'display:none', :class => 'detach-widget') %></a>
0
+ <a href="#"><%= image_tag('mephisto/icons/8-em-plus.png', :size => '16x16', :id => widget.dom_id("attach-#{prefix}-widget"),
0
+ :style => 'display:none', :class => 'attach-widget') %></a>
0
 </li>
0
\ No newline at end of file
...
22
23
24
 
25
26
...
22
23
24
25
26
27
0
@@ -22,4 +22,5 @@ xm.entry 'xml:base' => home_url do
0
             #{sanitize_feed_content [article.excerpt_html, article.body_html].compact * "\n"}
0
           </content>}
0
   end
0
+ article.add_xml(xm)
0
 end
0
\ No newline at end of file
...
2
3
4
5
 
6
7
8
...
19
20
21
 
 
 
 
 
 
 
 
 
22
23
24
...
60
61
62
 
63
64
65
...
88
89
90
 
91
92
93
...
2
3
4
 
5
6
7
8
...
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
...
69
70
71
72
73
74
75
...
98
99
100
101
102
103
104
0
@@ -2,7 +2,7 @@
0
 # migrations feature of ActiveRecord to incrementally modify your database, and
0
 # then regenerate this schema definition.
0
 
0
-ActiveRecord::Schema.define(:version => 69) do
0
+ActiveRecord::Schema.define(:version => 70) do
0
 
0
   create_table "assets", :force => true do |t|
0
     t.column "content_type", :string
0
@@ -19,6 +19,15 @@ ActiveRecord::Schema.define(:version => 69) do
0
     t.column "user_id", :integer
0
   end
0
 
0
+ create_table "assigned_assets", :force => true do |t|
0
+ t.column "article_id", :integer
0
+ t.column "asset_id", :integer
0
+ t.column "position", :integer
0
+ t.column "label", :string
0
+ t.column "created_at", :datetime
0
+ t.column "active", :boolean
0
+ end
0
+
0
   create_table "assigned_sections", :force => true do |t|
0
     t.column "article_id", :integer
0
     t.column "section_id", :integer
0
@@ -60,6 +69,7 @@ ActiveRecord::Schema.define(:version => 69) do
0
     t.column "filter", :string
0
     t.column "user_agent", :string
0
     t.column "referrer", :string
0
+ t.column "assets_count", :integer, :default => 0
0
   end
0
 
0
   create_table "contents", :force => true do |t|
0
@@ -88,6 +98,7 @@ ActiveRecord::Schema.define(:version => 69) do
0
     t.column "filter", :string
0
     t.column "user_agent", :string
0
     t.column "referrer", :string
0
+ t.column "assets_count", :integer, :default => 0
0
   end
0
 
0
   create_table "events", :force => true do |t|
...
206
207
208
209
 
210
211
 
212
213
214
...
295
296
297
298
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
299
300
301
...
548
549
550
 
 
 
 
 
 
 
551
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
552
553
554
...
206
207
208
 
209
210
 
211
212
213
214
...
295
296
297
 
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
...
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
0
@@ -206,9 +206,9 @@ TinyTab.prototype = {
0
 Asset = {
0
   upload: function(form) {
0
     form = $(form);
0
- article_id = location.href.match(/\/edit\/([0-9]+)/);
0
+ article_id = location.href.match(/\/(edit|upload)\/([0-9]+)/);
0
     form.action = Mephisto.root + "/admin/articles/upload"
0
- if(article_id) form.action += "/" + article_id[1]
0
+ if(article_id) form.action += "/" + article_id[2]
0
     form.submit();
0
   },
0
   
0
@@ -295,7 +295,32 @@ var ArticleForm = {
0
   getAvailableComments: function() {
0
     return $$('ul.commentlist li').reject(function(div) { return !(div.visible() && !div.hasClassName('disabled') && div.id.match(/^comment-/)); }).collect(function(div) { return div.id.match(/comment-(\d+)/)[1] });
0
   },
0
-
0
+
0
+ attachAsset: function(assetId) {
0
+ var articleId = location.href.match(/\/(edit|upload)\/([0-9]+)/)[2];
0
+ var attached = $('attached-widget-' + assetId);
0
+ if(attached) return;
0
+ new Ajax.Request('/admin/articles/attach/' + articleId + '/' + assetId);
0
+ $$('.widget').each(function(asset) { if(assetId == asset.getAttribute('id').match(/-(\d+)$/)[1]) asset.addClassName('selected-widget'); });
0
+ },
0
+
0
+ labelAsset: function(assetId) {
0
+ var articleId = location.href.match(/\/(edit|upload)\/([0-9]+)/)[2];
0
+ var attached = $('attached-widget-' + assetId);
0
+ var label = $('attached-widget-version-' + assetId);
0
+ new Ajax.Request('/admin/articles/label/' + articleId + '/' + assetId + '?label=' + escape(label.value));
0
+ if(attached) return;
0
+ },
0
+
0
+ detachAsset: function(assetId) {
0
+ var articleId = location.href.match(/\/(edit|upload)\/([0-9]+)/)[2];
0
+ var attached = $('attached-widget-' + assetId);
0
+ if(!attached) return;
0
+ new Ajax.Request('/admin/articles/detach/' + articleId + '/' + assetId);
0
+ new Effect.DropOut(attached, {afterFinish: function() { attached.remove(); }});
0
+ $$('.widget').each(function(asset) { if(assetId == asset.getAttribute('id').match(/-(\d+)$/)[1]) asset.removeClassName('selected-widget'); });
0
+ },
0
+
0
   getRevision: function() {
0
     var rev = $F(this)
0
     var url = Mephisto.root + '/admin/articles/edit/' + location.href.match(/\/edit\/([0-9]+)/)[1];
0
@@ -548,7 +573,37 @@ Event.addBehavior({
0
     $('published').value = '0';
0
     $('article-search').submit();
0
   },
0
+
0
+ 'li.widget:mouseover': function() {
0
+ var attach = $('attach-' + this.getAttribute('id'));
0
+ var detach = $('detach-' + this.getAttribute('id'));
0
+ if(attach) attach.show();
0
+ if(detach) detach.show();
0
+ },
0
   
0
+ 'li.widget:mouseout': function() {
0
+ var attach = $('attach-' + this.getAttribute('id'));
0
+ var detach = $('detach-' + this.getAttribute('id'));
0
+ if(attach) attach.hide();
0
+ if(detach) detach.hide();
0
+ },
0
+
0
+ '.attach-widget:click': function() {
0
+ ArticleForm.attachAsset(this.getAttribute('id').match(/-(\d+)$/)[1]);
0
+ return false;
0
+ },
0
+
0
+ '.label-widget:click': function() {
0
+ ArticleForm.labelAsset(this.getAttribute('id').match(/-(\d+)$/)[1]);
0
+ this.innerHTML = 'Saving...'
0
+ return false;
0
+ },
0
+
0
+ '.detach-widget:click': function() {
0
+ ArticleForm.detachAsset(this.getAttribute('id').match(/-(\d+)$/)[1]);
0
+ return false;
0
+ },
0
+
0
   'a.theme_dialog:click': function() {
0
     var img = this.down('img');
0
     var pieces = img.src.split('/');
...
1305
1306
1307
1308
 
1309
1310
1311
1312
1313
 
1314
 
1315
1316
1317
1318
1319
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1320
1321
1322
 
 
1323
1324
1325
1326
1327
1328
1329
1330
 
1331
1332
1333
...
1335
1336
1337
 
 
 
 
1338
1339
1340
...
1305
1306
1307
 
1308
1309
1310
1311
1312
 
1313
1314
1315
1316
1317
1318
1319
 
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
 
1370
1371
1372
1373
1374
1375
 
 
 
 
1376
1377
1378
1379
...
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
0
@@ -1305,29 +1305,75 @@ li.event-article { background-image: url(/images/mephisto/icons/articleb.gif);
0
  *=ASSET MANAGEMENT
0
  */
0
 
0
-#assets, #files, #latest-assets, #bucket-assets, #search-assets {
0
+#assets, #files, ul.asset-list {
0
   list-style: none;
0
   margin-top: 5px;
0
 }
0
 
0
-#assets li, #files li, #latest-assets li, #bucket-assets li, #search-assets li {
0
+#assets li, #files li, ul.asset-list li {
0
   display: inline;
0
+ white-space: no-wrap;
0
   margin-left: 5px;
0
   margin-bottom: 5px;
0
 }
0
 
0
-#assets li a img,
0
+#attached-assets li {
0
+ display:block;
0
+}
0
+
0
+#attached-assets li div {
0
+ position:relative;
0
+}
0
+
0
+#attached-assets li div a {
0
+ display:inline;
0
+}
0
+
0
+#attached-assets div input.txt {
0
+ width:125px;
0
+}
0
+
0
+#attached-assets div span {
0
+ position:absolute;
0
+ top:20px; right:8px;
0
+}
0
+
0
+ul.asset-list .widget {
0
+ position:relative;
0
+}
0
+
0
+.widget .attach-widget {
0
+ z-index:500;
0
+ position:absolute;
0
+ top:-13px; left:-23px;
0
+}
0
+
0
+.widget .detach-widget {
0
+ z-index:500;
0
+ position:absolute;
0
+ top:-36px; left:-23px;
0
+}
0
+
0
+#attached-assets .widget .attach-widget {
0
+ position:absolute;
0
+ top:11px; left:-23px;
0
+}
0
+
0
+#attached-assets .widget .detach-widget {
0
+ position:absolute;
0
+ top:34px; left:-23px;
0
+}
0
+
0
+#assets li a img,
0
 #latest-assets li a img,
0
 #bucket-assets li a img,
0
-#search-assets li a img {
0
+#search-assets li a img,
0
+ul.asset-list li a img {
0
   padding: 4px;
0
   background: #fff;
0
 }
0
 
0
-#assets img,
0
-#latest-assets img,
0
-#bucket-assets img,
0
-#search-assets img {
0
+ul.asset-list img {
0
   max-height: 50px;
0
   max-width: 50px;
0
   padding: 3px;
0
@@ -1335,6 +1381,10 @@ li.event-article { background-image: url(/images/mephisto/icons/articleb.gif);
0
   border: 1px solid #8BCACD;
0
 }
0
 
0
+ul.asset-list .selected-widget img {
0
+ border-color:#000;
0
+}
0
+
0
 #assets span,
0
 #latest-assets span,
0
 #bucket-assets span,
...
5
6
7
8
 
9
10
11
...
15
16
17
18
 
19
20
21
...
25
26
27
28
 
29
30
31
...
37
38
39
40
 
41
42
43
...
48
49
50
51
 
52
53
54
...
61
62
63
64
 
65
66
67
...
69
70
71
72
 
73
74
75
...
78
79
80
81
 
82
83
84
...
94
95
96
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
97
98
99
...
5
6
7
 
8
9
10
11
...
15
16
17
 
18
19
20
21
...
25
26
27
 
28
29
30
31
...
37
38
39
 
40
41
42
43
...
48
49
50
 
51
52
53
54
...
61
62
63
 
64
65
66
67
...
69
70
71
 
72
73
74
75
...
78
79
80
 
81
82
83
84
...
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
0
@@ -5,7 +5,7 @@ require 'admin/articles_controller'
0
 class Admin::ArticlesController; def rescue_action(e) raise e end; end
0
 
0
 class Admin::ArticlesControllerAssetsTest < Test::Unit::TestCase
0
- fixtures :contents, :content_versions, :sections, :assigned_sections, :users, :sites, :tags, :taggings, :memberships
0
+ fixtures :contents, :content_versions, :sections, :assigned_sections, :users, :sites, :tags, :taggings, :memberships, :assigned_assets, :assets
0
 
0
   def setup
0
     @controller = Admin::ArticlesController.new
0
@@ -15,7 +15,7 @@ class Admin::ArticlesControllerAssetsTest < Test::Unit::TestCase
0
     FileUtils.mkdir_p ASSET_PATH
0
   end
0
 
0
- def test_should_upload_asset
0
+ specify "should upload asset" do
0
     asset_count = has_image_processor? ? 3 : 1 # asset + 2 thumbnails
0
     
0
     assert_difference Asset, :count, asset_count do
0
@@ -25,7 +25,7 @@ class Admin::ArticlesControllerAssetsTest < Test::Unit::TestCase
0
     end
0
   end
0
 
0
- def test_should_upload_asset_and_redirect_to_article
0
+ specify "should upload asset and redirect to article" do
0
     asset_count = has_image_processor? ? 3 : 1 # asset + 2 thumbnails
0
     
0
     assert_difference Asset, :count, asset_count do
0
@@ -37,7 +37,7 @@ class Admin::ArticlesControllerAssetsTest < Test::Unit::TestCase
0
     end
0
   end
0
 
0
- def test_should_upload_asset_as_member
0
+ specify "should upload asset as member" do
0
     asset_count = has_image_processor? ? 3 : 1 # asset + 2 thumbnails
0
     
0
     login_as :ben
0
@@ -48,7 +48,7 @@ class Admin::ArticlesControllerAssetsTest < Test::Unit::TestCase
0
     end
0
   end
0
 
0
- def test_should_upload_asset_and_redirect_to_article_as_member
0
+ specify "should upload asset and redirect to article as member" do
0
     asset_count = has_image_processor? ? 3 : 1 # asset + 2 thumbnails
0
     
0
     login_as :ben
0
@@ -61,7 +61,7 @@ class Admin::ArticlesControllerAssetsTest < Test::Unit::TestCase
0
     end
0
   end
0
 
0
- def test_should_not_error_on_new_article_asset_upload
0
+ specify "should not error on new article asset upload" do
0
     assert_no_difference Asset, :count do
0
       post :upload
0
       assert_response :success
0
@@ -69,7 +69,7 @@ class Admin::ArticlesControllerAssetsTest < Test::Unit::TestCase
0
     end
0
   end
0
 
0
- def test_should_not_error_on_article_asset_upload
0
+ specify "should not error on article asset upload" do
0
     assert_no_difference Asset, :count do
0
       post :upload, :id => contents(:welcome).id
0
       assert_response :success
0
@@ -78,7 +78,7 @@ class Admin::ArticlesControllerAssetsTest < Test::Unit::TestCase
0
     end
0
   end
0
 
0
- def test_should_not_create_article_when_uploading_asset
0
+ specify "should not create article when uploading asset" do
0
     Time.mock! Time.local(2005, 1, 1, 12, 0, 0) do
0
       assert_no_difference Article, :count do
0
         post :upload, :asset => { :uploaded_data => fixture_file_upload('assets/logo.png', 'image/png') },
0
@@ -94,6 +94,29 @@ class Admin::ArticlesControllerAssetsTest < Test::Unit::TestCase
0
     end
0
   end
0
 
0
+ specify "should add asset to article" do
0
+ assert_difference AssignedAsset, :count do
0
+ post :attach, :id => contents(:welcome).id, :version => assets(:mov).id, :label => 'avatar'
0
+ end
0
+ assert_models_equal [assets(:gif), assets(:mp3), assets(:mov)], contents(:welcome).assets(true)
0
+ assert_equal 'avatar', contents(:welcome).assets[2].label
0
+ end
0
+
0
+ specify "should add inactive asset to article" do
0
+ assert_no_difference AssignedAsset, :count do
0
+ post :attach, :id => contents(:welcome).id, :version => assets(:png).id, :label => 'avatar'
0
+ end
0
+ assert_models_equal [assets(:gif), assets(:mp3), assets(:png)], contents(:welcome).assets(true)
0
+ assert_equal 'avatar', contents(:welcome).assets[2].label
0
+ end
0
+
0
+ specify "should find deactivate article assets" do
0
+ assert_no_difference AssignedAsset, :count do
0
+ post :detach, :id => contents(:welcome).id, :version => assets(:mp3).id
0
+ end
0
+ assert_models_equal [assets(:gif)], contents(:welcome).assets
0
+ end
0
+
0
   def teardown
0
     FileUtils.rm_rf ASSET_PATH
0
   end