active_sort_order 0.9.0 → 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,6 +3,16 @@ ENV["RAILS_ENV"] = "test"
3
3
 
4
4
  require "active_sort_order"
5
5
 
6
+ begin
7
+ require 'warning'
8
+
9
+ Warning.ignore(
10
+ %r{mail/parsers/address_lists_parser}, ### Hide mail gem warnings
11
+ )
12
+ rescue LoadError
13
+ # Do nothing
14
+ end
15
+
6
16
  ### Instantiates Rails
7
17
  require File.expand_path("../dummy_app/config/environment.rb", __FILE__)
8
18
 
@@ -34,12 +44,12 @@ else
34
44
  end
35
45
 
36
46
  [Post].each do |klass|
37
- ### REGULAR SQL
38
- #ActiveRecord::Base.connection.execute("TRUNCATE TABLE #{klass.table_name}")
39
-
40
- ### SQLITE
41
- ActiveRecord::Base.connection.execute("DELETE FROM #{klass.table_name};")
42
- ActiveRecord::Base.connection.execute("UPDATE `sqlite_sequence` SET `seq` = 0 WHERE `name` = '#{klass.table_name}';")
47
+ if defined?(SQLite3)
48
+ ActiveRecord::Base.connection.execute("DELETE FROM #{klass.table_name};")
49
+ ActiveRecord::Base.connection.execute("UPDATE `sqlite_sequence` SET `seq` = 0 WHERE `name` = '#{klass.table_name}';")
50
+ else
51
+ ActiveRecord::Base.connection.execute("TRUNCATE TABLE #{klass.table_name}")
52
+ end
43
53
  end
44
54
 
45
55
  DATA = {}.with_indifferent_access
@@ -2,10 +2,10 @@ require "test_helper"
2
2
 
3
3
  class ActiveSortOrderTest < ActiveSupport::TestCase
4
4
 
5
- def setup
5
+ setup do
6
6
  end
7
7
 
8
- def teardown
8
+ teardown do
9
9
  end
10
10
 
11
11
  def test_exposes_main_module
@@ -16,6 +16,14 @@ class ActiveSortOrderTest < ActiveSupport::TestCase
16
16
  assert ActiveSortOrder::VERSION
17
17
  end
18
18
 
19
+ def test_base_sort_order_default_value
20
+ klass = PostWithBaseOrderA
21
+
22
+ assert PostWithBaseOrderA.unscoped.sort_order.to_sql.include?("ORDER BY #{klass.base_sort_order}")
23
+
24
+ assert PostWithBaseOrderA.unscoped.sort_order(base_sort_order: true).to_sql.include?("ORDER BY #{klass.base_sort_order}")
25
+ end
26
+
19
27
  def test_class_base_sort_order_only
20
28
  assert_equal Post.all.count, DATA[:posts].count
21
29
 
@@ -2,10 +2,10 @@ require "test_helper"
2
2
 
3
3
  class ActiveSortOrderTest < ActiveSupport::TestCase
4
4
 
5
- def setup
5
+ setup do
6
6
  end
7
7
 
8
- def teardown
8
+ teardown do
9
9
  end
10
10
 
11
11
  def test_sort_str_errors
@@ -29,6 +29,10 @@ class ActiveSortOrderTest < ActiveSupport::TestCase
29
29
  Object.new,
30
30
  ]
31
31
 
32
+ if RUBY_VERSION.to_f >= 3.0
33
+ invalid << {}
34
+ end
35
+
32
36
  invalid.each do |v|
33
37
  assert_raise ArgumentError do
34
38
  Post.sort_order(v, :asc).limit(1)
@@ -41,16 +45,18 @@ class ActiveSortOrderTest < ActiveSupport::TestCase
41
45
 
42
46
  ### TEST UNIQUE CASES
43
47
 
44
- ### HASH - this is allowed because its treated as keyword arguments
45
- Post.sort_order({}).limit(1)
48
+ if RUBY_VERSION.to_f < 3.0
49
+ ### HASH - this is allowed because its treated as keyword arguments
50
+ Post.sort_order({}).limit(1)
46
51
 
47
- assert_raise do
48
- Post.sort_order({}, :desc).limit(1)
52
+ assert_raise do
53
+ Post.sort_order({}, :desc).limit(1)
54
+ end
49
55
  end
50
56
  end
51
57
 
52
58
  def test_sort_direction_errors
53
- valid_directions = [
59
+ valid = [
54
60
  "ASC",
55
61
  "DESC",
56
62
  "ASC NULLS FIRST",
@@ -67,7 +73,7 @@ class ActiveSortOrderTest < ActiveSupport::TestCase
67
73
  "ASC\tNULLS\tFirst",
68
74
  ].freeze
69
75
 
70
- valid_directions.each do |direction|
76
+ valid.each do |direction|
71
77
  PostWithBaseOrderA.sort_order("x", direction).limit(1)
72
78
 
73
79
  if direction
@@ -81,15 +87,19 @@ class ActiveSortOrderTest < ActiveSupport::TestCase
81
87
  end
82
88
  end
83
89
 
84
- bad_directions = [
90
+ invalid = [
85
91
  false,
86
92
  true,
87
93
  Object.new,
88
94
  [],
89
95
  'ASCC',
90
- ].freeze
96
+ ]
91
97
 
92
- bad_directions.each do |direction|
98
+ if RUBY_VERSION.to_f >= 3.0
99
+ invalid << {}
100
+ end
101
+
102
+ invalid.each do |direction|
93
103
  assert_raise ArgumentError do
94
104
  PostWithBaseOrderA.sort_order("foobar", direction).limit(1)
95
105
  end
@@ -97,17 +107,22 @@ class ActiveSortOrderTest < ActiveSupport::TestCase
97
107
 
98
108
  ### TEST UNIQUE CASES
99
109
 
100
- ### HASH - this is allowed because its treated as keyword arguments
101
- Post.sort_order("foobar", {}).limit(1).to_sql.include?("foobar ASC")
110
+ if RUBY_VERSION.to_f < 3.0
111
+ ### HASH - this is allowed because its treated as keyword arguments
112
+ Post.sort_order("foobar", {}).limit(1).to_sql.include?("foobar ASC")
102
113
 
103
- assert_raise do
104
- Post.sort_order("foobar", {}, {}).limit(1)
114
+ assert_raise do
115
+ Post.sort_order("foobar", {}, {}).limit(1)
116
+ end
105
117
  end
106
118
  end
107
119
 
108
- def test_base_sort_order_errors
120
+ def test_argument_base_sort_order_errors
121
+ assert_not Post.respond_to?(:base_sort_order)
122
+
109
123
  valid = [
110
124
  nil,
125
+ true,
111
126
  false,
112
127
  "",
113
128
  "foobar",
@@ -129,8 +144,13 @@ class ActiveSortOrderTest < ActiveSupport::TestCase
129
144
  Post.sort_order(base_sort_order: v).limit(1)
130
145
  end
131
146
  end
147
+ end
148
+
149
+ def test_class_method_base_sort_order_errors
150
+ klass = PostWithVolatileBaseOrder
151
+
152
+ assert klass.respond_to?(:base_sort_order)
132
153
 
133
- ### INVALID BASE_SORT_ORDER CLASS
134
154
  valid = [
135
155
  nil,
136
156
  false,
@@ -140,15 +160,22 @@ class ActiveSortOrderTest < ActiveSupport::TestCase
140
160
 
141
161
  valid.each do |v|
142
162
  silence_warnings do
143
- PostWithVolatileBaseOrder.define_method :base_sort_order do
163
+ klass.define_singleton_method :base_sort_order do
144
164
  v
145
165
  end
146
166
  end
147
167
 
148
- PostWithVolatileBaseOrder.sort_order(base_sort_order: v).limit(1)
168
+ if v.nil?
169
+ assert_nil klass.base_sort_order
170
+ else
171
+ assert_equal v, klass.base_sort_order
172
+ end
173
+
174
+ klass.sort_order.limit(1)
149
175
  end
150
176
 
151
177
  invalid = [
178
+ true,
152
179
  :foobar,
153
180
  [],
154
181
  {},
@@ -157,13 +184,19 @@ class ActiveSortOrderTest < ActiveSupport::TestCase
157
184
 
158
185
  invalid.each do |v|
159
186
  silence_warnings do
160
- PostWithVolatileBaseOrder.define_method :base_sort_order do
187
+ klass.define_singleton_method :base_sort_order do
161
188
  v
162
189
  end
163
190
  end
164
191
 
192
+ if v.nil?
193
+ assert_nil klass.base_sort_order
194
+ else
195
+ assert_equal v, klass.base_sort_order
196
+ end
197
+
165
198
  assert_raise ArgumentError do
166
- PostWithVolatileBaseOrder.sort_order(base_sort_order: v).limit(1)
199
+ klass.sort_order.limit(1)
167
200
  end
168
201
  end
169
202
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_sort_order
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Weston Ganger
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-29 00:00:00.000000000 Z
11
+ date: 2021-02-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -16,29 +16,16 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '5'
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
- version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: railties
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
- description: Dead simple, fully customizable sorting pattern for ActiveRecord.
26
+ version: '5'
27
+ description: The "easy-peasy" dynamic sorting pattern for ActiveRecord that your Rails
28
+ apps deserve.
42
29
  email:
43
30
  - weston@westonganger.com
44
31
  executables: []
@@ -64,7 +51,6 @@ files:
64
51
  - test/dummy_app/app/models/post_with_base_order_b.rb
65
52
  - test/dummy_app/app/models/post_with_base_order_b_and_a.rb
66
53
  - test/dummy_app/app/models/post_with_volatile_base_order.rb
67
- - test/dummy_app/app/models/test_helper.rb
68
54
  - test/dummy_app/app/views/layouts/application.html.erb
69
55
  - test/dummy_app/config.ru
70
56
  - test/dummy_app/config/application.rb
@@ -104,7 +90,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
104
90
  requirements:
105
91
  - - ">="
106
92
  - !ruby/object:Gem::Version
107
- version: 2.3.0
93
+ version: '0'
108
94
  required_rubygems_version: !ruby/object:Gem::Requirement
109
95
  requirements:
110
96
  - - ">="
@@ -114,12 +100,12 @@ requirements: []
114
100
  rubygems_version: 3.1.2
115
101
  signing_key:
116
102
  specification_version: 4
117
- summary: Dead simple, fully customizable sorting pattern for ActiveRecord.
103
+ summary: The "easy-peasy" dynamic sorting pattern for ActiveRecord that your Rails
104
+ apps deserve.
118
105
  test_files:
119
106
  - test/test_helper.rb
120
107
  - test/unit/active_sort_order_test.rb
121
108
  - test/unit/errors_test.rb
122
- - test/dummy_app/app/models/test_helper.rb
123
109
  - test/dummy_app/app/models/post_with_volatile_base_order.rb
124
110
  - test/dummy_app/app/models/post_with_base_order_a_and_b.rb
125
111
  - test/dummy_app/app/models/application_record.rb
File without changes