contentment 0.3.2 → 0.4.0
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.
@@ -29,19 +29,11 @@ class Content < ActiveRecord::Base
|
|
29
29
|
|
30
30
|
private
|
31
31
|
def adjust_positions
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
# unless x.position > self.position
|
38
|
-
# if x.position
|
39
|
-
# x.update_attribute :position, x.position + 1
|
40
|
-
# else
|
41
|
-
# x.update_attribute :position, self.position + idx
|
42
|
-
# end
|
43
|
-
# end
|
44
|
-
# end
|
32
|
+
return true unless changed.include?('position')
|
33
|
+
return true unless brothers.map{|x| x.position}.include?(self.position)
|
34
|
+
|
35
|
+
brothers.where("position < ?", self.position).update_all("position = (position - 1)")
|
36
|
+
brothers.where("position >= ?", self.position).update_all("position = (position + 1)")
|
45
37
|
end
|
46
38
|
|
47
39
|
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ContentTest < ActiveSupport::TestCase
|
4
|
+
# Replace this with your real tests.
|
5
|
+
test "content should fix position on save" do
|
6
|
+
a = Content.create(:position => 1, :title => 'a', :tipe => 'test')
|
7
|
+
b = Content.create(:position => 2, :title => 'b', :tipe => 'test')
|
8
|
+
c = Content.create(:position => 3, :title => 'c', :tipe => 'test')
|
9
|
+
c.position = 1
|
10
|
+
c.save
|
11
|
+
|
12
|
+
assert(c.reload.position == 1)
|
13
|
+
assert(a.reload.position == 2)
|
14
|
+
assert(b.reload.position == 3)
|
15
|
+
end
|
16
|
+
end
|
@@ -25,6 +25,7 @@ class ContentmentGenerator < Rails::Generators::Base
|
|
25
25
|
# Need to figure out how to ask the user if they would like to overwrite their model.
|
26
26
|
else
|
27
27
|
template 'content.rb', content_model
|
28
|
+
template 'content_test.rb', 'test/unit/content_test.rb'
|
28
29
|
end
|
29
30
|
|
30
31
|
contents_controller = 'app/controllers/contents_controller.rb'
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
7
|
+
- 4
|
8
|
+
- 0
|
9
|
+
version: 0.4.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Bob Larrick
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-01-
|
17
|
+
date: 2011-01-12 00:00:00 -05:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|
@@ -38,6 +38,7 @@ files:
|
|
38
38
|
- lib/generators/contentment/contentment_views_templates/contents/show.html.erb
|
39
39
|
- lib/generators/contentment/contentment_views_templates/contents_helper.rb
|
40
40
|
- lib/generators/contentment/templates/content.rb
|
41
|
+
- lib/generators/contentment/templates/content_test.rb
|
41
42
|
- lib/generators/contentment/templates/contents_controller.rb
|
42
43
|
- lib/generators/contentment/templates/migration.rb
|
43
44
|
- lib/generators/contentment_generator.rb
|