rails_sortable 1.4.1 → 1.5.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: dd026aa907b8fe7622e414a6db047b695d1099e0c919aafbfe0c76d30ee9169b
4
- data.tar.gz: 74fedcd695978d5dc394935139c3df0d00b1083e6426cffb01c1b07ae7716a39
3
+ metadata.gz: c44dbc38b1087772a6f32c4db9aa581b453635e689934c4997e60c4ccd1eb11d
4
+ data.tar.gz: 947a084a93b82ceda59f03ca652e6d3faa147a3bb8246e7a3f6cb04e662efc88
5
5
  SHA512:
6
- metadata.gz: e026c27c509126c9a816a39a3b79a97985e84792df7b5844548f69d5c2d83f089392c8885842d6452b8bdfb94cabf3a2a9434cedf586ab2394e2810969c211c7
7
- data.tar.gz: a5b2e05a81a5a458ab5a7eff4c122b4406499808da22e3343aa2ec9573e56b242ba8a216c9be2e2e91349754f2e05836feff839a87c4106323f8a0691136d9d5
6
+ metadata.gz: 30d37231a74a61c303360dd18dabe5708614bc8378816327f67e4fcad51c3b0c893bb457cf95cf28c4c49f3f4e8935a48d844dee15b68677705f75829f5895c5
7
+ data.tar.gz: bfb2153e6ccee626fffff36bbc6ca1418755d4643eabc96fe31d68e509c6e7406be63d583eb0cfb886a4e9b9676e59fa37bf0fbacd3040a859acd1a90207fac0
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, use the following option.
49
- # set_sortable :sort, without_updating_timestamps: true
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 rspecs
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 { save! }
25
+ without_updating_timestamps { save_as_desired }
25
26
  elsif self.class.sortable_options[:without_updating_timestamps]
26
- without_updating_timestamps { save! }
27
+ without_updating_timestamps { save_as_desired }
27
28
  else
28
- save!
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,3 +1,3 @@
1
1
  module RailsSortable
2
- VERSION = '1.4.1'
2
+ VERSION = '1.5.0'
3
3
  end
@@ -0,0 +1,4 @@
1
+ class ValidatedItem < Item
2
+ self.table_name = "items"
3
+ validates_presence_of :title
4
+ end
@@ -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
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.1
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - itmammoth
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-01 00:00:00.000000000 Z
11
+ date: 2022-03-12 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
@@ -184,7 +199,7 @@ homepage: https://github.com/itmammoth/rails_sortable
184
199
  licenses:
185
200
  - MIT
186
201
  metadata: {}
187
- post_install_message:
202
+ post_install_message:
188
203
  rdoc_options: []
189
204
  require_paths:
190
205
  - lib
@@ -199,8 +214,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
199
214
  - !ruby/object:Gem::Version
200
215
  version: '0'
201
216
  requirements: []
202
- rubygems_version: 3.1.4
203
- signing_key:
217
+ rubygems_version: 3.3.8
218
+ signing_key:
204
219
  specification_version: 4
205
220
  summary: Easy drag & drop sorting for rails.
206
221
  test_files:
@@ -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