randumb 0.5.2 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/randumb/relation.rb +4 -9
- data/lib/randumb/version.rb +1 -1
- data/test/models/factories.rb +1 -1
- data/test/randumb_test.rb +11 -11
- data/test/test_helper.rb +3 -1
- data/test/weighted_test.rb +2 -2
- metadata +69 -28
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 9fd0e54ae7de8a15766df8a33d65edd4a5d1eab2cb3ba36b27c6f9541ab39a72
|
4
|
+
data.tar.gz: ed1afd68fa829e7e236d92d44fda28439492b004eda2c8d45b11b1b85f8feee3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7031236bbde306b4c508d019956514ebe0a9b93b037f0d2cc2a539ea694b55c33c05b6728cfaae952f663b2727f919b974a863ddc905b15c77e70ca99c149c91
|
7
|
+
data.tar.gz: 7431df3f579c21e3076507b85564375646db6e78135ac0420d399c62e50474bafe3a1d827bc1f174edb57f22c8a68dbbaf7eb6b8e656e845e23476dfbb4bc310
|
data/lib/randumb/relation.rb
CHANGED
@@ -91,15 +91,10 @@ module Randumb
|
|
91
91
|
Randumb::Syntax.random_order_clause(opts)
|
92
92
|
end
|
93
93
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
# keep prior orders and append random
|
99
|
-
all_orders = (orders + [order_clause])
|
100
|
-
# override all previous orders
|
101
|
-
reorder(all_orders)
|
102
|
-
end
|
94
|
+
# keep prior orders and append random
|
95
|
+
all_orders = (arel.orders + [order_clause])
|
96
|
+
# override all previous orders
|
97
|
+
reorder(all_orders)
|
103
98
|
end
|
104
99
|
|
105
100
|
# postgres won't let you do an order_by when also doing a distinct
|
data/lib/randumb/version.rb
CHANGED
data/test/models/factories.rb
CHANGED
data/test/randumb_test.rb
CHANGED
@@ -39,7 +39,7 @@ class RandumbTest < Minitest::Test
|
|
39
39
|
|
40
40
|
context "1 record in the table" do
|
41
41
|
setup do
|
42
|
-
@high_on_fire =
|
42
|
+
@high_on_fire = FactoryBot.create(:artist, :name => "High On Fire", :views => 1)
|
43
43
|
end
|
44
44
|
|
45
45
|
should "select only 1 record even when you request more" do
|
@@ -67,8 +67,8 @@ class RandumbTest < Minitest::Test
|
|
67
67
|
|
68
68
|
context "3 records in table" do
|
69
69
|
setup do
|
70
|
-
@fiona_apple =
|
71
|
-
@magnetic_fields =
|
70
|
+
@fiona_apple = FactoryBot.create(:artist, :name => "Fiona Apple", :views => 3)
|
71
|
+
@magnetic_fields = FactoryBot.create(:artist, :name => "The Magnetic Fields", :views => 2)
|
72
72
|
end
|
73
73
|
|
74
74
|
should "apply randomness after other orders when using sql method" do
|
@@ -124,10 +124,10 @@ class RandumbTest < Minitest::Test
|
|
124
124
|
|
125
125
|
context "with some albums" do
|
126
126
|
setup do
|
127
|
-
@tidal =
|
128
|
-
@extraordinary_machine =
|
129
|
-
@sixty_nine_love_songs =
|
130
|
-
@snakes_for_the_divine =
|
127
|
+
@tidal = FactoryBot.create(:album, :name => "Tidal", :artist => @fiona_apple)
|
128
|
+
@extraordinary_machine = FactoryBot.create(:album, :name => "Extraordinary Machine", :artist => @fiona_apple)
|
129
|
+
@sixty_nine_love_songs = FactoryBot.create(:album, :name => "69 Love Songs", :artist => @magnetic_fields)
|
130
|
+
@snakes_for_the_divine = FactoryBot.create(:album, :name => "Snakes For the Divine", :artist => @high_on_fire)
|
131
131
|
end
|
132
132
|
|
133
133
|
|
@@ -135,7 +135,7 @@ class RandumbTest < Minitest::Test
|
|
135
135
|
artists = Artist.includes(:albums).random(10)
|
136
136
|
fiona_apple = artists.find { |a| a.name == "Fiona Apple" }
|
137
137
|
# if I add a new album now, it shouldn't be in the albums assocation yet b/c it was already loaded
|
138
|
-
|
138
|
+
FactoryBot.create(:album, :name => "When The Pawn", :artist => @fiona_apple)
|
139
139
|
|
140
140
|
assert_equal 2, fiona_apple.albums.length
|
141
141
|
assert_equal 3, @fiona_apple.reload.albums.length
|
@@ -145,7 +145,7 @@ class RandumbTest < Minitest::Test
|
|
145
145
|
artists = Artist.includes(:albums).random_by_id_shuffle(10)
|
146
146
|
fiona_apple = artists.find { |a| a.name == "Fiona Apple" }
|
147
147
|
# if I add a new album now, it shouldn't be in the albums assocation yet b/c it was already loaded
|
148
|
-
|
148
|
+
FactoryBot.create(:album, :name => "When The Pawn", :artist => @fiona_apple)
|
149
149
|
|
150
150
|
assert_equal 2, fiona_apple.albums.length
|
151
151
|
assert_equal 3, @fiona_apple.reload.albums.length
|
@@ -189,8 +189,8 @@ class RandumbTest < Minitest::Test
|
|
189
189
|
|
190
190
|
context "2 records in table" do
|
191
191
|
setup do
|
192
|
-
@hum =
|
193
|
-
@minutemen =
|
192
|
+
@hum = FactoryBot.create(:artist, :name => "Hum", :views => 3)
|
193
|
+
@minutemen = FactoryBot.create(:artist, :name => "Minutemen", :views => 2)
|
194
194
|
end
|
195
195
|
|
196
196
|
should "eventually render the 2 possible orders using default method" do
|
data/test/test_helper.rb
CHANGED
@@ -2,7 +2,7 @@ $LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
|
|
2
2
|
require 'rubygems'
|
3
3
|
require "minitest/autorun"
|
4
4
|
require 'shoulda'
|
5
|
-
require '
|
5
|
+
require 'factory_bot'
|
6
6
|
require 'faker'
|
7
7
|
require 'active_record'
|
8
8
|
require 'active_support/dependencies'
|
@@ -22,6 +22,8 @@ commands = {
|
|
22
22
|
}
|
23
23
|
%x{#{commands[driver] || true}}
|
24
24
|
|
25
|
+
|
26
|
+
|
25
27
|
ActiveRecord::Base.establish_connection config[driver]
|
26
28
|
puts "Using #{RUBY_VERSION} AR #{version} with #{driver}"
|
27
29
|
|
data/test/weighted_test.rb
CHANGED
@@ -41,7 +41,7 @@ class WeightedTest < Minitest::Test
|
|
41
41
|
end
|
42
42
|
|
43
43
|
should "not interfere with active record dynamic methods that use method_missing" do
|
44
|
-
@artist =
|
44
|
+
@artist = FactoryBot.create(:artist, :name => 'Spiritualized')
|
45
45
|
assert_equal @artist, Artist.find_by_name('Spiritualized')
|
46
46
|
end
|
47
47
|
|
@@ -59,7 +59,7 @@ class WeightedTest < Minitest::Test
|
|
59
59
|
context "order by ranking_column" do
|
60
60
|
setup do
|
61
61
|
@view_counts = [1, 2, 3, 4, 5]
|
62
|
-
@view_counts.each { |views|
|
62
|
+
@view_counts.each { |views| FactoryBot.create(:artist, views: views) }
|
63
63
|
end
|
64
64
|
|
65
65
|
should "respect default scope" do
|
metadata
CHANGED
@@ -1,139 +1,181 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: randumb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zachary Kloepping
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-05-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: activesupport
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: 3.0.20
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 3.0.20
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: activerecord
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: 3.0.20
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 3.0.20
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: sqlite3
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: 1.3.6
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: 1.3.6
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: mysql2
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.4.10
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.4.10
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pg
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.19.0
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.19.0
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: bigdecimal
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 1.4.2
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 1.4.2
|
69
111
|
- !ruby/object:Gem::Dependency
|
70
112
|
name: minitest
|
71
113
|
requirement: !ruby/object:Gem::Requirement
|
72
114
|
requirements:
|
73
|
-
- -
|
115
|
+
- - ">="
|
74
116
|
- !ruby/object:Gem::Version
|
75
117
|
version: '0'
|
76
118
|
type: :development
|
77
119
|
prerelease: false
|
78
120
|
version_requirements: !ruby/object:Gem::Requirement
|
79
121
|
requirements:
|
80
|
-
- -
|
122
|
+
- - ">="
|
81
123
|
- !ruby/object:Gem::Version
|
82
124
|
version: '0'
|
83
125
|
- !ruby/object:Gem::Dependency
|
84
126
|
name: shoulda
|
85
127
|
requirement: !ruby/object:Gem::Requirement
|
86
128
|
requirements:
|
87
|
-
- -
|
129
|
+
- - ">="
|
88
130
|
- !ruby/object:Gem::Version
|
89
131
|
version: '0'
|
90
132
|
type: :development
|
91
133
|
prerelease: false
|
92
134
|
version_requirements: !ruby/object:Gem::Requirement
|
93
135
|
requirements:
|
94
|
-
- -
|
136
|
+
- - ">="
|
95
137
|
- !ruby/object:Gem::Version
|
96
138
|
version: '0'
|
97
139
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
140
|
+
name: factory_bot
|
99
141
|
requirement: !ruby/object:Gem::Requirement
|
100
142
|
requirements:
|
101
|
-
- -
|
143
|
+
- - ">="
|
102
144
|
- !ruby/object:Gem::Version
|
103
145
|
version: '0'
|
104
146
|
type: :development
|
105
147
|
prerelease: false
|
106
148
|
version_requirements: !ruby/object:Gem::Requirement
|
107
149
|
requirements:
|
108
|
-
- -
|
150
|
+
- - ">="
|
109
151
|
- !ruby/object:Gem::Version
|
110
152
|
version: '0'
|
111
153
|
- !ruby/object:Gem::Dependency
|
112
154
|
name: faker
|
113
155
|
requirement: !ruby/object:Gem::Requirement
|
114
156
|
requirements:
|
115
|
-
- -
|
157
|
+
- - ">="
|
116
158
|
- !ruby/object:Gem::Version
|
117
159
|
version: '0'
|
118
160
|
type: :development
|
119
161
|
prerelease: false
|
120
162
|
version_requirements: !ruby/object:Gem::Requirement
|
121
163
|
requirements:
|
122
|
-
- -
|
164
|
+
- - ">="
|
123
165
|
- !ruby/object:Gem::Version
|
124
166
|
version: '0'
|
125
167
|
- !ruby/object:Gem::Dependency
|
126
168
|
name: pry
|
127
169
|
requirement: !ruby/object:Gem::Requirement
|
128
170
|
requirements:
|
129
|
-
- -
|
171
|
+
- - ">="
|
130
172
|
- !ruby/object:Gem::Version
|
131
173
|
version: '0'
|
132
174
|
type: :development
|
133
175
|
prerelease: false
|
134
176
|
version_requirements: !ruby/object:Gem::Requirement
|
135
177
|
requirements:
|
136
|
-
- -
|
178
|
+
- - ">="
|
137
179
|
- !ruby/object:Gem::Version
|
138
180
|
version: '0'
|
139
181
|
description:
|
@@ -142,10 +184,10 @@ executables: []
|
|
142
184
|
extensions: []
|
143
185
|
extra_rdoc_files: []
|
144
186
|
files:
|
187
|
+
- lib/randumb.rb
|
145
188
|
- lib/randumb/relation.rb
|
146
189
|
- lib/randumb/syntax.rb
|
147
190
|
- lib/randumb/version.rb
|
148
|
-
- lib/randumb.rb
|
149
191
|
- test/models/album.rb
|
150
192
|
- test/models/artist.rb
|
151
193
|
- test/models/factories.rb
|
@@ -162,17 +204,16 @@ require_paths:
|
|
162
204
|
- lib
|
163
205
|
required_ruby_version: !ruby/object:Gem::Requirement
|
164
206
|
requirements:
|
165
|
-
- -
|
207
|
+
- - ">="
|
166
208
|
- !ruby/object:Gem::Version
|
167
209
|
version: '0'
|
168
210
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
169
211
|
requirements:
|
170
|
-
- -
|
212
|
+
- - ">="
|
171
213
|
- !ruby/object:Gem::Version
|
172
214
|
version: '0'
|
173
215
|
requirements: []
|
174
|
-
|
175
|
-
rubygems_version: 2.0.14.1
|
216
|
+
rubygems_version: 3.0.3
|
176
217
|
signing_key:
|
177
218
|
specification_version: 4
|
178
219
|
summary: Adds the ability to pull random records from ActiveRecord
|