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 !
scope site section ordering to the current site object, so its called like 
site.sections.order instead of Section.order

git-svn-id: http://svn.techno-weenie.net/projects/mephisto/trunk@2292 
567b1171-46fb-0310-a4c9-b4bef9110e78
technoweenie (author)
Tue Sep 26 23:06:47 -0700 2006
commit  1da1ea5e583cb806314d4b7438c61d4af161c07e
tree    d4590b6400e8bfc21c4eabc4be78fb817df3f605
parent  09396e763e1d2b8dad71216c5b6a9b212a2ca72a
...
26
27
28
29
 
30
31
32
...
26
27
28
 
29
30
31
32
0
@@ -26,7 +26,7 @@ class Admin::SectionsController < Admin::BaseController
0
 
0
   def order
0
     if params[:id].to_i == 0
0
- Section.order! params[:sorted_ids]
0
+ site.sections.order! params[:sorted_ids]
0
     else
0
       find_section
0
       @section.order! params[:sorted_ids]
...
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
...
35
36
37
 
 
 
 
 
 
 
 
 
38
39
40
0
@@ -35,15 +35,6 @@ class Section < ActiveRecord::Base
0
     def permalink_for(str)
0
       str.gsub(/[^\w\/]|[!\(\)\.]+/, ' ').strip.downcase.gsub(/\ +/, '-')
0
     end
0
-
0
- # orders sections in a site
0
- def order!(*sorted_ids)
0
- sorted_ids.flatten.each_with_index do |section_id, pos|
0
- section = find(section_id)
0
- section.position = pos
0
- section.save
0
- end
0
- end
0
   end
0
 
0
   def find_comments(options = {})
...
8
9
10
 
 
 
 
 
 
 
 
 
11
12
13
...
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
0
@@ -8,6 +8,15 @@ class Site < ActiveRecord::Base
0
     def home
0
       find_by_path ''
0
     end
0
+
0
+ # orders sections in a site
0
+ def order!(*sorted_ids)
0
+ transaction do
0
+ sorted_ids.flatten.each_with_index do |section_id, pos|
0
+ Section.update_all ['position = ?', pos], ['id = ? and site_id = ?', section_id, proxy_owner.id]
0
+ end
0
+ end
0
+ end
0
   end
0
 
0
   has_many :articles do
...
113
114
115
116
117
118
119
120
121
122
123
...
125
126
127
128
129
130
131
132
133
134
135
136
...
113
114
115
 
 
 
 
 
116
117
118
...
120
121
122
 
 
 
 
 
 
123
124
125
0
@@ -113,11 +113,6 @@ class SectionTest < Test::Unit::TestCase
0
       [contents(:about), contents(:site_map), contents(:welcome)]
0
   end
0
 
0
- specify "should order sections in site" do
0
- assert_reorder_sections [sections(:home), sections(:about), sections(:earth), sections(:europe), sections(:africa), sections(:bucharest), sections(:links)],
0
- [sections(:home), sections(:earth), sections(:europe), sections(:africa), sections(:bucharest), sections(:links), sections(:about)]
0
- end
0
-
0
   protected
0
     def assert_reorder_articles(section, old_order, expected)
0
       assert_models_equal old_order, section.articles
0
@@ -125,12 +120,6 @@ class SectionTest < Test::Unit::TestCase
0
       assert_models_equal expected, section.articles(true)
0
     end
0
     
0
- def assert_reorder_sections(old_order, expected)
0
- assert_models_equal old_order, sites(:first).sections
0
- Section.order! expected.collect(&:id)
0
- assert_models_equal expected, sites(:first).sections(true)
0
- end
0
-
0
     def test_should_report_section_types
0
       assert sections(:home).blog?
0
       [:about, :cupcake_home, :cupcake_about].each { |s| assert sections(s).paged? }
...
1
2
3
 
4
5
6
...
54
55
56
 
 
 
 
 
 
 
 
 
 
 
 
57
58
59
...
1
2
 
3
4
5
6
...
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
0
@@ -1,6 +1,6 @@
0
 require File.dirname(__FILE__) + '/../test_helper'
0
 context "Site" do
0
- fixtures :sites, :contents
0
+ fixtures :sites, :contents, :sections
0
 
0
   specify "should create site without accepting comments" do
0
     site = Site.new :host => 'foo.com', :comment_age => -1
0
@@ -54,6 +54,18 @@ context "Site" do
0
     assert_equal '/tags/foo', sites(:first).tag_url('foo')
0
     assert_equal '/tags/foo/bar', sites(:first).tag_url('foo', 'bar')
0
   end
0
+
0
+ specify "should order sections in site" do
0
+ assert_reorder_sections [sections(:home), sections(:about), sections(:earth), sections(:europe), sections(:africa), sections(:bucharest), sections(:links)],
0
+ [sections(:home), sections(:earth), sections(:europe), sections(:africa), sections(:bucharest), sections(:links), sections(:about)]
0
+ end
0
+
0
+ protected
0
+ def assert_reorder_sections(old_order, expected)
0
+ assert_models_equal old_order, sites(:first).sections
0
+ sites(:first).sections.order! expected.collect(&:id)
0
+ assert_models_equal expected, sites(:first).sections(true)
0
+ end
0
 end
0
 
0
 context "Site Membership" do

Comments

    No one has commented yet.