tiny_cms 0.2.4 → 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/lib/tiny_cms/node.rb +13 -6
- data/test/test_node.rb +5 -20
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.5
|
data/lib/tiny_cms/node.rb
CHANGED
@@ -29,6 +29,10 @@ module TinyCMS
|
|
29
29
|
|
30
30
|
model.named_scope :roots, :conditions => {:parent_id => nil}, :order => 'position'
|
31
31
|
|
32
|
+
model.named_scope :by_parent_id, lambda { |parent_id|
|
33
|
+
{:conditions => {:parent_id => parent_id}}
|
34
|
+
}
|
35
|
+
|
32
36
|
model.belongs_to :parent, :class_name => model.to_s, :foreign_key => 'parent_id'
|
33
37
|
model.has_many :children, :class_name => model.to_s, :foreign_key => 'parent_id', :order => 'position', :dependent => :destroy
|
34
38
|
|
@@ -48,12 +52,7 @@ module TinyCMS
|
|
48
52
|
end
|
49
53
|
model.alias_method_chain :children=, :position
|
50
54
|
end
|
51
|
-
|
52
|
-
def siblings
|
53
|
-
return [] unless parent_id
|
54
|
-
self.class.include_tree(1).find(:first, :conditions => "id = #{parent_id}").children.find(:all, :conditions => "id != #{id}")
|
55
|
-
end
|
56
|
-
|
55
|
+
|
57
56
|
def parameterize_permalink
|
58
57
|
text = permalink.blank? ? title : permalink
|
59
58
|
self.permalink = text.parameterize if text
|
@@ -67,6 +66,14 @@ module TinyCMS
|
|
67
66
|
{:attributes => {'data-node-id' => id, 'data-permalink' => permalink, 'data-path' => path}, :data => title, :children => children.map{ |c| c.to_hash } }
|
68
67
|
end
|
69
68
|
|
69
|
+
def siblings
|
70
|
+
section.find :all, :conditions => "id != #{id}"
|
71
|
+
end
|
72
|
+
|
73
|
+
def section
|
74
|
+
self.class.by_parent_id parent_id
|
75
|
+
end
|
76
|
+
|
70
77
|
def to_json opts = {}
|
71
78
|
self.to_hash.to_json
|
72
79
|
end
|
data/test/test_node.rb
CHANGED
@@ -94,12 +94,16 @@ class PageTest < Test::Unit::TestCase
|
|
94
94
|
end
|
95
95
|
|
96
96
|
should 'getting siblings for root' do
|
97
|
-
assert_equal [], @roots.first.siblings
|
97
|
+
assert_equal @roots[1..-1], @roots.first.siblings
|
98
98
|
end
|
99
99
|
|
100
100
|
should 'getting ordered root' do
|
101
101
|
assert_equal @roots.map(&:id), Page.roots.map(&:id)
|
102
102
|
end
|
103
|
+
|
104
|
+
should 'getting section' do
|
105
|
+
assert_equal @children, @children.first.section
|
106
|
+
end
|
103
107
|
end
|
104
108
|
|
105
109
|
context 'json generation' do
|
@@ -206,11 +210,6 @@ class PageTest < Test::Unit::TestCase
|
|
206
210
|
@page = Factory :page, :title => 'This is teh title', :permalink => nil
|
207
211
|
assert_equal 'this-is-teh-title', @page.permalink
|
208
212
|
end
|
209
|
-
|
210
|
-
# should 'convert to blank if permalink == index' do
|
211
|
-
# @page = Factory :page, :permalink => 'index'
|
212
|
-
# assert_equal '', @page.permalink
|
213
|
-
# end
|
214
213
|
end
|
215
214
|
|
216
215
|
context 'validation' do
|
@@ -234,14 +233,6 @@ class PageTest < Test::Unit::TestCase
|
|
234
233
|
assert_equal false, @page2.errors.on(:permalink).blank?
|
235
234
|
end
|
236
235
|
|
237
|
-
# should 'allow duplicate if path is the same but one is not page' do
|
238
|
-
# @page1.update_attribute
|
239
|
-
# assert_equal @page1.path, @page2.path
|
240
|
-
# assert_equal @page1.permalink, @page2.permalink
|
241
|
-
# @page1.save!
|
242
|
-
# assert_equal true, @page2.valid?
|
243
|
-
# end
|
244
|
-
|
245
236
|
should 'allow duplicate if paths are diferent and both are pages' do
|
246
237
|
@page2.parent = @page3
|
247
238
|
@page1.save(false)
|
@@ -253,12 +244,6 @@ class PageTest < Test::Unit::TestCase
|
|
253
244
|
assert_equal @page1.permalink, @page2.permalink
|
254
245
|
assert_equal true, @page2.valid?
|
255
246
|
end
|
256
|
-
|
257
|
-
# should 'validate presence of permalink if is not page' do
|
258
|
-
# page = Factory.build :page, :permalink => ''
|
259
|
-
# assert_equal false, page.valid?
|
260
|
-
# assert_equal false, page.errors.on(:permalink).blank?
|
261
|
-
# end
|
262
247
|
end
|
263
248
|
end
|
264
249
|
|