positionable 1.0.8 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: dea4446e013f0d3c7e57d4bf2e8d74c7af721686
4
+ data.tar.gz: 9970c900f6539bb9927e8453778a660e71a97499
5
+ SHA512:
6
+ metadata.gz: 5e4b68e82b37b1924ce4c867522459c0edf8f0b2bce39d1bacfbf9a4430c8a05eed4b914de6636950d7d059fff10816a33540578e2cb12f94896f6aee2c5cfb3
7
+ data.tar.gz: f62639878cbc83cfe151c1c4769baecdf42c785bab701f7cd1b2384d0a2376afbbe40ea816957dd7e4f6ce92ae8d2ca3726bde79f81688fea622b2b51c3eceac
@@ -66,7 +66,7 @@ module Positionable
66
66
  start = options[:start] || 0
67
67
  order = options[:order] || :asc
68
68
 
69
- default_scope order("\"#{self.table_name}\".\"position\" #{order}")
69
+ default_scope { order("#{ActiveRecord::Base.connection.quote_table_name self.table_name}.#{ActiveRecord::Base.connection.quote_column_name 'position'} #{order}") }
70
70
 
71
71
  before_create :add_to_bottom
72
72
  before_update :update_position
@@ -88,7 +88,11 @@ module Positionable
88
88
  # Does its best to retrieve the target scope...
89
89
  target_scope_id = scope.nil? ? scope_id : scope.id
90
90
  # Number of records whithin the target scope
91
- count = self.class.where("#{scope_id_attr} = ?", target_scope_id).count
91
+ count = if target_scope_id.nil?
92
+ self.class.where("#{scope_id_attr} IS NULL").count
93
+ else
94
+ self.class.where("#{scope_id_attr} = ?", target_scope_id).count
95
+ end
92
96
  # An additional position is available if this record is new, or if it's moved to another scope
93
97
  if new_record? or target_scope_id != scope_id
94
98
  (start..(start + count))
@@ -120,7 +124,11 @@ module Positionable
120
124
  end
121
125
 
122
126
  def scoped_condition_was
123
- "#{scope_id_attr} = " + scope_id_was.to_s
127
+ if scope_id_was.nil?
128
+ "#{scope_id_attr} IS NULL"
129
+ else
130
+ "#{scope_id_attr} = " + scope_id_was.to_s
131
+ end
124
132
  end
125
133
 
126
134
  def scoped_position_was
@@ -1,3 +1,3 @@
1
1
  module Positionable
2
- VERSION = "1.0.8"
2
+ VERSION = "1.1.1"
3
3
  end
@@ -24,5 +24,5 @@ Gem::Specification.new do |s|
24
24
  s.add_development_dependency "simplecov"
25
25
  s.add_development_dependency "factory_girl"
26
26
 
27
- s.add_runtime_dependency "activerecord", "~> 3.1"
27
+ s.add_runtime_dependency "activerecord", ">= 3.1"
28
28
  end
@@ -13,31 +13,25 @@ describe Positionable do
13
13
 
14
14
  it "does not extend non positionable models" do
15
15
  dummy = Dummy.new
16
- dummy.respond_to?(:previous).should be_false
17
- dummy.respond_to?(:next).should be_false
18
- dummy.respond_to?(:position=).should be_false
16
+ expect(dummy.respond_to?(:previous)).to eq(false)
17
+ expect(dummy.respond_to?(:next)).to eq(false)
18
+ expect(dummy.respond_to?(:position=)).to eq(false)
19
19
  end
20
20
 
21
21
  it "extends positionable models" do
22
22
  item = DefaultItem.new
23
- item.respond_to?(:previous).should be_true
24
- item.respond_to?(:next).should be_true
25
- item.respond_to?(:position=).should be_true
26
- end
27
-
28
- it "prepends the table name in SQL 'order by' clause" do
29
- sql = DefaultItem.where("1 = 1").to_sql
30
- table = DefaultItem.table_name
31
- sql.should include("ORDER BY \"#{table}\".\"position\"")
23
+ expect(item.respond_to?(:previous)).to eq(true)
24
+ expect(item.respond_to?(:next)).to eq(true)
25
+ expect(item.respond_to?(:position=)).to eq(true)
32
26
  end
33
27
 
34
28
  context "inheritance" do
35
29
 
36
30
  it "extends positionable sub-models" do
37
31
  item = SubItem1.new
38
- item.respond_to?(:previous).should be_true
39
- item.respond_to?(:next).should be_true
40
- item.respond_to?(:position=).should be_true
32
+ expect(item.respond_to?(:previous)).to eq(true)
33
+ expect(item.respond_to?(:next)).to eq(true)
34
+ expect(item.respond_to?(:position=)).to eq(true)
41
35
  end
42
36
 
43
37
  end
@@ -5,7 +5,6 @@ end
5
5
  class Document < ActiveRecord::Base
6
6
  belongs_to :folder
7
7
  is_positionable :scope => :folder
8
- attr_accessible :position, :folder_id
9
8
  end
10
9
 
11
10
  class Item < ActiveRecord::Base
@@ -40,7 +39,6 @@ end
40
39
  class ComplexItem < Item
41
40
  belongs_to :group
42
41
  is_positionable :scope => :group, :order => :desc, :start => 1
43
- attr_accessible :position, :group_id
44
42
  end
45
43
 
46
44
  class Dummy < ActiveRecord::Base
metadata CHANGED
@@ -1,110 +1,97 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: positionable
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.8
5
- prerelease:
4
+ version: 1.1.1
6
5
  platform: ruby
7
6
  authors:
8
7
  - Philippe Guégan
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-12-11 00:00:00.000000000 Z
11
+ date: 2014-07-09 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: bundler
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
19
  version: 1.0.0
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - ">="
28
25
  - !ruby/object:Gem::Version
29
26
  version: 1.0.0
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rspec
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ~>
31
+ - - "~>"
36
32
  - !ruby/object:Gem::Version
37
33
  version: '2.3'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ~>
38
+ - - "~>"
44
39
  - !ruby/object:Gem::Version
45
40
  version: '2.3'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: sqlite3
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - ">="
52
46
  - !ruby/object:Gem::Version
53
47
  version: '0'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - ">="
60
53
  - !ruby/object:Gem::Version
61
54
  version: '0'
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: simplecov
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ! '>='
59
+ - - ">="
68
60
  - !ruby/object:Gem::Version
69
61
  version: '0'
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ! '>='
66
+ - - ">="
76
67
  - !ruby/object:Gem::Version
77
68
  version: '0'
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: factory_girl
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
- - - ! '>='
73
+ - - ">="
84
74
  - !ruby/object:Gem::Version
85
75
  version: '0'
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
- - - ! '>='
80
+ - - ">="
92
81
  - !ruby/object:Gem::Version
93
82
  version: '0'
94
83
  - !ruby/object:Gem::Dependency
95
84
  name: activerecord
96
85
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
86
  requirements:
99
- - - ~>
87
+ - - ">="
100
88
  - !ruby/object:Gem::Version
101
89
  version: '3.1'
102
90
  type: :runtime
103
91
  prerelease: false
104
92
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
93
  requirements:
107
- - - ~>
94
+ - - ">="
108
95
  - !ruby/object:Gem::Version
109
96
  version: '3.1'
110
97
  description: This extension provides contiguous positionning capabilities to your
@@ -115,8 +102,8 @@ executables: []
115
102
  extensions: []
116
103
  extra_rdoc_files: []
117
104
  files:
118
- - .gitignore
119
- - .travis.yml
105
+ - ".gitignore"
106
+ - ".travis.yml"
120
107
  - Gemfile
121
108
  - LICENCE
122
109
  - README.rdoc
@@ -132,27 +119,26 @@ files:
132
119
  - spec/support/schema.rb
133
120
  homepage: https://github.com/pguegan/positionable
134
121
  licenses: []
122
+ metadata: {}
135
123
  post_install_message:
136
124
  rdoc_options: []
137
125
  require_paths:
138
126
  - lib
139
127
  required_ruby_version: !ruby/object:Gem::Requirement
140
- none: false
141
128
  requirements:
142
- - - ! '>='
129
+ - - ">="
143
130
  - !ruby/object:Gem::Version
144
131
  version: '0'
145
132
  required_rubygems_version: !ruby/object:Gem::Requirement
146
- none: false
147
133
  requirements:
148
- - - ! '>='
134
+ - - ">="
149
135
  - !ruby/object:Gem::Version
150
136
  version: '0'
151
137
  requirements: []
152
138
  rubyforge_project: positionable
153
- rubygems_version: 1.8.24
139
+ rubygems_version: 2.2.2
154
140
  signing_key:
155
- specification_version: 3
141
+ specification_version: 4
156
142
  summary: A gem for positionning your ActiveRecord models.
157
143
  test_files:
158
144
  - spec/factories.rb