rails_sortable 1.4.1 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7a7af5d942a8451358e832b796966b930246a268ada95a911e3d2ffd8cf77a83
|
4
|
+
data.tar.gz: 67cb118503633f2e882f92bfbe97585a7f5f9f636d8534b3365989b636fbb2bc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3169f4792bad6175e85872eb8bdc048607218ca925c81d75567fd4474ca1769728692fef7d09006e1dedaf88ff4fd8edc862650b9da2764622972924d91d7874
|
7
|
+
data.tar.gz: 15976342a3f98e750b5f319c01c4720d9c357c5e8ad1ba775079066609533392e3e0ab5d6f33c0b8c57515d09a46dea0423f8f16a98584102c86985e93a9ee5d
|
data/README.md
CHANGED
@@ -45,8 +45,9 @@ and `Item` model as
|
|
45
45
|
class Item < ApplicationRecord
|
46
46
|
include RailsSortable::Model
|
47
47
|
set_sortable :sort # Indicate a sort column
|
48
|
-
# If you do NOT want timestamps to be updated on sorting
|
49
|
-
#
|
48
|
+
# without_updating_timestamps: true, # If you do NOT want timestamps to be updated on sorting
|
49
|
+
# without_validations: true # If you do NOT want validations to be run on sorting
|
50
|
+
|
50
51
|
end
|
51
52
|
```
|
52
53
|
and `ItemsController` as
|
@@ -113,9 +114,10 @@ Please give me a PR freely.
|
|
113
114
|
$ spec/dummy/bin/rails db:migrate
|
114
115
|
$ spec/dummy/bin/rails s
|
115
116
|
# Insert test data
|
117
|
+
$ RAILS_ENV=test spec/dummy/bin/rails db:migrate
|
116
118
|
$ spec/dummy/bin/rails db:seed
|
117
119
|
|
118
|
-
# Run
|
120
|
+
# Run specs
|
119
121
|
$ bundle exec rspec
|
120
122
|
```
|
121
123
|
|
@@ -19,13 +19,14 @@ module RailsSortable
|
|
19
19
|
|
20
20
|
def update_sort!(new_value)
|
21
21
|
write_attribute sort_attribute, new_value
|
22
|
+
|
22
23
|
if self.class.sortable_options[:silence_recording_timestamps]
|
23
24
|
warn "[DEPRECATION] `silence_recording_timestamps` is deprecated. Please use `without_updating_timestamps` instead."
|
24
|
-
without_updating_timestamps {
|
25
|
+
without_updating_timestamps { save_as_desired }
|
25
26
|
elsif self.class.sortable_options[:without_updating_timestamps]
|
26
|
-
without_updating_timestamps {
|
27
|
+
without_updating_timestamps { save_as_desired }
|
27
28
|
else
|
28
|
-
|
29
|
+
save_as_desired
|
29
30
|
end
|
30
31
|
end
|
31
32
|
|
@@ -52,6 +53,10 @@ module RailsSortable
|
|
52
53
|
(self.class.maximum(sort_attribute) || 0) + 1
|
53
54
|
end
|
54
55
|
|
56
|
+
def save_as_desired
|
57
|
+
self.class.sortable_options[:without_validations] ? save(validate: false) : save!
|
58
|
+
end
|
59
|
+
|
55
60
|
def sort_attribute
|
56
61
|
self.class.sort_attribute
|
57
62
|
end
|
@@ -61,6 +66,8 @@ module RailsSortable
|
|
61
66
|
# allowed options
|
62
67
|
# - without_updating_timestamps
|
63
68
|
# When it is true, timestamp(updated_at) will be NOT touched on reordering.
|
69
|
+
# - without_validations
|
70
|
+
# When it is true, validations will be skipped
|
64
71
|
#
|
65
72
|
def set_sortable(attribute, options = {})
|
66
73
|
self.define_singleton_method(:sort_attribute) { attribute }
|
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe RailsSortable::Model, type: :model do
|
4
|
-
|
5
4
|
describe "before_create" do
|
6
5
|
context "when sort is nil" do
|
7
6
|
it "should be automatically set maximum sort value" do
|
@@ -51,6 +50,38 @@ describe RailsSortable::Model, type: :model do
|
|
51
50
|
end
|
52
51
|
end
|
53
52
|
end
|
53
|
+
|
54
|
+
describe "without_validations" do
|
55
|
+
context "when optional value is true" do
|
56
|
+
before do
|
57
|
+
ValidatedItem.class_eval do
|
58
|
+
set_sortable :sort, without_validations: true
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
it "will skip validations" do
|
63
|
+
item = ValidatedItem.create!(title: "Title")
|
64
|
+
item.update_attribute(:title, nil)
|
65
|
+
expect { item.update_sort!(1000) }.not_to raise_error
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context "when optional value is false" do
|
70
|
+
before do
|
71
|
+
ValidatedItem.class_eval do
|
72
|
+
set_sortable :sort, without_validations: false
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
it "will require validations" do
|
77
|
+
item = ValidatedItem.create!(title: "Title")
|
78
|
+
item.update_attribute(:title, nil)
|
79
|
+
expect do
|
80
|
+
item.update_sort!(1000)
|
81
|
+
end.to raise_error(ActiveRecord::RecordInvalid, /Title can't be blank/)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
54
85
|
end
|
55
86
|
|
56
87
|
describe "sortable_id" do
|
@@ -3,6 +3,8 @@
|
|
3
3
|
$.fn.railsSortable = function(options) {
|
4
4
|
options = options || {};
|
5
5
|
var settings = $.extend({}, options);
|
6
|
+
|
7
|
+
settings.baseUrl = settings.baseUrl || '';
|
6
8
|
|
7
9
|
settings.update = function(event, ui) {
|
8
10
|
if (typeof options.update === 'function') {
|
@@ -11,7 +13,7 @@
|
|
11
13
|
|
12
14
|
$.ajax({
|
13
15
|
type: 'POST',
|
14
|
-
url: '/sortable/reorder',
|
16
|
+
url: settings.baseUrl + '/sortable/reorder',
|
15
17
|
dataType: 'json',
|
16
18
|
contentType: 'application/json',
|
17
19
|
data: JSON.stringify({
|
@@ -22,4 +24,4 @@
|
|
22
24
|
|
23
25
|
this.sortable(settings);
|
24
26
|
};
|
25
|
-
})(jQuery);
|
27
|
+
})(jQuery);
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_sortable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- itmammoth
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-03-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -94,6 +94,20 @@ dependencies:
|
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: 0.3.0
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: puma
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 5.6.0
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 5.6.0
|
97
111
|
description: rails_sortable provides easy drag & drop sorting for rails 4 and 5.
|
98
112
|
email:
|
99
113
|
- itmammoth@gmail.com
|
@@ -134,6 +148,7 @@ files:
|
|
134
148
|
- spec/dummy/app/models/item.rb
|
135
149
|
- spec/dummy/app/models/second_item.rb
|
136
150
|
- spec/dummy/app/models/sequenced_item.rb
|
151
|
+
- spec/dummy/app/models/validated_item.rb
|
137
152
|
- spec/dummy/app/views/items/_form.html.erb
|
138
153
|
- spec/dummy/app/views/items/edit.html.erb
|
139
154
|
- spec/dummy/app/views/items/index.html.erb
|
@@ -199,7 +214,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
199
214
|
- !ruby/object:Gem::Version
|
200
215
|
version: '0'
|
201
216
|
requirements: []
|
202
|
-
rubygems_version: 3.
|
217
|
+
rubygems_version: 3.4.6
|
203
218
|
signing_key:
|
204
219
|
specification_version: 4
|
205
220
|
summary: Easy drag & drop sorting for rails.
|
@@ -226,6 +241,7 @@ test_files:
|
|
226
241
|
- spec/dummy/app/models/item.rb
|
227
242
|
- spec/dummy/app/models/second_item.rb
|
228
243
|
- spec/dummy/app/models/sequenced_item.rb
|
244
|
+
- spec/dummy/app/models/validated_item.rb
|
229
245
|
- spec/dummy/app/views/items/_form.html.erb
|
230
246
|
- spec/dummy/app/views/items/edit.html.erb
|
231
247
|
- spec/dummy/app/views/items/index.html.erb
|