ranked-model 0.4.2 → 0.4.3

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
  SHA1:
3
- metadata.gz: 5cfad22b2acf05bc3deda080d1bb11b96ade3c9d
4
- data.tar.gz: cd2d02de24cf6465ee4211818beb6696ec41e616
3
+ metadata.gz: 8b5933c81c7b8db9b1a26b327b7805d0aa0f6334
4
+ data.tar.gz: eaf6954358557ed51528cf76d9848f6d3961a7a1
5
5
  SHA512:
6
- metadata.gz: fd1dbb2069c730aeda634d15cc4cd5a5fa0be8def4cca8db3b6bb320e40ef97f29f88bac16f2ba12720a1287cbb06ae3188e7862f5586599757fc2c56f6d3e6e
7
- data.tar.gz: b5f0896c2a4979b3f8d157bc20f3ee1bc7846ea6ef2ffb3432b50d5696e0852f803026bea3d0177c8db22b949c3d8c89022582b4c79da84c8ff8fc4a2611d3a6
6
+ metadata.gz: 1b905fc8d5ffb24b27eacbe3de7a7de5be4ff16c23ed2ca6256a1a73f6424076660bbbd74f1b99e472421f50fcd637c2732edf574a22f217ad8963af0f418901
7
+ data.tar.gz: f917f55c584657fe4d744592e04f131ec7cf58e9cf3abba73b532075a2776ec21d759d488d028e413deaedc946bf9b91b2b5a4c72980a2f535c46cfbc6e59cf9
@@ -45,3 +45,5 @@ matrix:
45
45
  gemfile: gemfiles/rails_4_1.gemfile
46
46
  - rvm: 2.5.1
47
47
  gemfile: gemfiles/rails_4_1.gemfile
48
+ - rvm: rbx-3.107
49
+ gemfile: gemfiles/rails_5_2.gemfile
@@ -3,6 +3,8 @@ require File.dirname(__FILE__)+'/ranked-model/railtie' if defined?(Rails::Railti
3
3
 
4
4
  module RankedModel
5
5
 
6
+ class NonNilColumnDefault < StandardError; end
7
+
6
8
  # Signed INT in MySQL
7
9
  #
8
10
  MAX_RANK_VALUE = 2147483647
@@ -18,7 +20,7 @@ module RankedModel
18
20
  before_save :handle_ranking
19
21
 
20
22
  scope :rank, lambda { |name|
21
- order ranker(name.to_sym).column
23
+ reorder ranker(name.to_sym).column
22
24
  }
23
25
  end
24
26
 
@@ -45,6 +47,11 @@ module RankedModel
45
47
  def ranks *args
46
48
  self.rankers ||= []
47
49
  ranker = RankedModel::Ranker.new(*args)
50
+
51
+ if column_defaults[ranker.name.to_s]
52
+ raise NonNilColumnDefault, %Q{Your ranked model column "#{ranker.name}" must not have a default value in the database.}
53
+ end
54
+
48
55
  self.rankers << ranker
49
56
  attr_reader "#{ranker.name}_position"
50
57
  define_method "#{ranker.name}_position=" do |position|
@@ -205,7 +205,7 @@ module RankedModel
205
205
  end
206
206
 
207
207
  def rebalance_ranks
208
- if rank
208
+ if rank && instance.persisted?
209
209
  origin = current_order.index { |item| item.instance.id == instance.id }
210
210
  destination = current_order.index { |item| rank <= item.rank }
211
211
  destination -= 1 if origin < destination
@@ -256,7 +256,7 @@ module RankedModel
256
256
  _finder = _finder.where.not instance_class.primary_key.to_sym => instance.id
257
257
  end
258
258
 
259
- _finder.order(ranker.column.to_sym => order).select(columns)
259
+ _finder.reorder(ranker.column.to_sym => order).select(columns)
260
260
  end
261
261
  end
262
262
 
@@ -1,3 +1,3 @@
1
1
  module RankedModel
2
- VERSION = "0.4.2"
2
+ VERSION = "0.4.3"
3
3
  end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'ColumnDefaultDuck' do
4
+
5
+ it "should raise an error if we try to initialise ranked_model on a column with a default value" do
6
+ expect {
7
+ class ColumnDefaultDuck < ActiveRecord::Base
8
+ include RankedModel
9
+ ranks :size, :with_same => :pond
10
+ end
11
+ }.to raise_error(RankedModel::NonNilColumnDefault, 'Your ranked model column "size" must not have a default value in the database.')
12
+ end
13
+
14
+ end
@@ -29,6 +29,8 @@ RSpec.configure do |config|
29
29
  DatabaseCleaner.clean
30
30
  end
31
31
 
32
+ config.order = :random
33
+ Kernel.srand config.seed
32
34
  end
33
35
 
34
36
  RSpec::Matchers.define :define_constant do |expected|
@@ -33,6 +33,12 @@ ActiveRecord::Schema.define :version => 0 do
33
33
  t.string :pond
34
34
  end
35
35
 
36
+ create_table :column_default_ducks, :force => true do |t|
37
+ t.string :name
38
+ t.integer :size, default: 0
39
+ t.string :pond
40
+ end
41
+
36
42
  create_table :elements, :force => true do |t|
37
43
  t.string :symbol
38
44
  t.string :type
@@ -17,6 +17,6 @@ postgresql:
17
17
  database: ranked_model_test
18
18
  pool: 5
19
19
  timeout: 5000
20
- username: postgres
20
+ username: brendon
21
21
  password:
22
22
  min_messages: ERROR
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ranked-model
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Beale
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-12-09 00:00:00.000000000 Z
11
+ date: 2019-02-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -150,6 +150,7 @@ files:
150
150
  - lib/ranked-model/version.rb
151
151
  - rails/init.rb
152
152
  - ranked-model.gemspec
153
+ - spec/duck-model/column_default_ducks_spec.rb
153
154
  - spec/duck-model/duck_spec.rb
154
155
  - spec/duck-model/lots_of_ducks_spec.rb
155
156
  - spec/duck-model/wrong_ducks_spec.rb
@@ -189,6 +190,7 @@ signing_key:
189
190
  specification_version: 4
190
191
  summary: An acts_as_sortable replacement built for Rails 3 & 4
191
192
  test_files:
193
+ - spec/duck-model/column_default_ducks_spec.rb
192
194
  - spec/duck-model/duck_spec.rb
193
195
  - spec/duck-model/lots_of_ducks_spec.rb
194
196
  - spec/duck-model/wrong_ducks_spec.rb