public
Fork of halorgium/mephisto
Description: A mirror of the mephisto code-base
Homepage: http://mephistoblog.com/
Clone URL: git://github.com/technoweenie/mephisto.git
Click here to lend your support to: mephisto and make a donation at www.pledgie.com !
add tagging to articles, fix obscure comment/event bug when updating 
article filters

git-svn-id: http://svn.techno-weenie.net/projects/mephisto/trunk@1809 
567b1171-46fb-0310-a4c9-b4bef9110e78
technoweenie (author)
Sat Aug 19 07:14:09 -0700 2006
commit  ca137987f2cebaef9289827aad41791ef8c3e2a6
tree    e833747d9f2542b50d122a03d6b043600ac63f86
parent  3309c47f842f21184bcde122c62e06f63ab73b0f
...
1
 
2
3
4
 
5
6
7
...
1
2
3
4
 
5
6
7
8
0
@@ -1,7 +1,8 @@
0
 class CommentObserver < ArticleObserver
0
+ cattr_accessor :disabled
0
   def after_save(record)
0
     @event.update_attributes :title => record.article.title, :body => record.body, :site => record.article.site,
0
- :article => record.article, :author => record.author, :comment => record if record.approved?
0
+ :article => record.article, :author => record.author, :comment => record if record.approved? && !disabled
0
   end
0
 
0
   def after_destroy(record)
...
1
2
 
 
 
3
4
5
...
107
108
109
110
 
 
111
112
113
...
167
168
169
170
 
 
171
172
173
174
175
 
 
176
177
178
...
1
2
3
4
5
6
7
8
...
110
111
112
 
113
114
115
116
117
...
171
172
173
 
174
175
176
177
178
179
 
180
181
182
183
184
0
@@ -1,5 +1,8 @@
0
 class Article < Content
0
   class CommentNotAllowed < StandardError; end
0
+
0
+ include Mephisto::TaggableMethods
0
+
0
   validates_presence_of :title, :user_id, :site_id
0
 
0
   before_validation { |record| record.set_default_filter! }
0
@@ -107,7 +110,8 @@ class Article < Content
0
   end
0
 
0
   def filter=(new_filter)
0
- @old_filter ||= read_attribute :filter
0
+ return if new_filter == read_attribute(:filter)
0
+ @old_filter ||= read_attribute(:filter)
0
     write_attribute :filter, new_filter
0
   end
0
 
0
@@ -167,11 +171,13 @@ class Article < Content
0
     
0
     def pass_filter_to_comments
0
       return unless @old_filter
0
- self.record_timestamps = false
0
+ self.record_timestamps = false
0
+ CommentObserver.disabled = true
0
       comments.each { |c| c.update_attributes(:filter => filter) }
0
       @old_filter = nil
0
       true
0
     ensure
0
- self.record_timestamps = true
0
+ self.record_timestamps = true
0
+ CommentObserver.disabled = false
0
     end
0
 end
0
\ No newline at end of file
...
27
28
29
30
 
31
32
33
...
27
28
29
 
30
31
32
33
0
@@ -27,7 +27,7 @@ class Tagging < ActiveRecord::Base
0
     # Tagging.add_to taggable, [Tag, Tag, Tag]
0
     def add_to(taggable, tags)
0
       (tags - taggable.tags).each do |tag|
0
- create! :taggable => taggable, :tag => tag
0
+ tg= create! :taggable => taggable, :tag => tag
0
       end unless tags.empty?
0
     end
0
   end
...
9
10
11
 
 
12
13
14
...
9
10
11
12
13
14
15
16
0
@@ -9,6 +9,8 @@
0
     <dd id="x-body" style="display:none"><%= form.text_area :excerpt, :rows => '8', :class => 'fat' %></dd>
0
     <dt><label for="article_body">Write your article</label> <span class="hint">(<%= link_to_function 'Add an excerpt', %(Element.toggle('x-lbl', 'x-body')) %>)</span></dt>
0
     <dd><%= form.text_area :body, :class => 'fat' %></dd>
0
+ <dt><label for="article_tag">Tags</label> <span class="hint">Enter one or more tags separated by a comma.</span></dt>
0
+ <dd><%= form.text_field :tag %></dd>
0
   </dl>
0
 </div>
0
 <!-- /end required fields -->
...
1
2
3
4
 
5
6
7
...
1
2
3
 
4
5
6
7
0
@@ -1,7 +1,7 @@
0
 <dl class="group">
0
   <dt><label for="asset_title">Title</label></dt>
0
   <dd><%= form.text_field :title %></dd>
0
- <dt><label for="asset_tag">Tag</label></dt>
0
+ <dt><label for="asset_tag">Tags</label> <span class="hint">Enter one or more tags separated by a comma.</span></dt>
0
   <dd><%= form.text_field :tag %></dd>
0
   <dt><label for="asset_uploaded_data">Upload</label></dt>
0
   <dd><%= form.file_field :uploaded_data %></dd>
...
2
3
4
5
 
6
7
8
...
2
3
4
 
5
6
7
8
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 => 46) do
0
+ActiveRecord::Schema.define(:version => 47) do
0
 
0
   create_table "assets", :force => true do |t|
0
     t.column "content_type", :string
...
131
132
133
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
134
135
136
...
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
0
@@ -131,6 +131,23 @@ class ArticleTest < Test::Unit::TestCase
0
     assert_equal User.find_with_deleted(3), contents(:another).user
0
   end
0
 
0
+ def test_should_set_tags
0
+ assert_equal '', contents(:welcome).tag
0
+ assert_difference Tagging, :count, 2 do
0
+ contents(:welcome).update_attribute :tag, 'ruby, rails'
0
+ end
0
+ assert_equal 'rails, ruby', contents(:welcome).reload.tag
0
+ end
0
+
0
+ def test_should_set_tags_upon_article_creation
0
+ a = nil
0
+ assert_difference Tagging, :count, 2 do
0
+ a = create_article :tag => 'ruby, rails', :body => 'foo'
0
+ assert_valid a
0
+ end
0
+ assert_equal 'rails, ruby', a.reload.tag
0
+ end
0
+
0
   protected
0
     def create_article(options = {})
0
       Article.create options.reverse_merge(:user_id => 1, :site_id => 1, :title => 'foo')
...
15
16
17
18
19
 
 
 
 
20
21
22
...
15
16
17
 
 
18
19
20
21
22
23
24
0
@@ -15,8 +15,10 @@ class EventTest < Test::Unit::TestCase
0
   end
0
 
0
   def test_should_create_edit_article_event
0
- assert_event_created_for :welcome, 'edit' do |article|
0
- article.update_attributes :title => 'foo', :body => 'bar', :updater => users(:quentin)
0
+ assert_difference Event, :count do
0
+ assert_event_created_for :welcome, 'edit' do |article|
0
+ article.update_attributes :title => 'foo', :body => 'bar', :updater => users(:quentin), :filter => 'markdown_filter'
0
+ end
0
     end
0
   end
0
 

Comments

    No one has commented yet.