active_sort_order 0.9.3 → 0.9.4

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: '089c16d2abd0a4aeb75c3a377d54f70883a7397758841c55f7bb64940cb3b205'
4
- data.tar.gz: caf3be0137352d2c1df913f9bdf6749253d15e7ed852d1bba646a2ce58fe90f4
3
+ metadata.gz: 863fc9f8899a7aea2e126c5f482b1bb8d422513c644eaf26f4f58fbc52d82f6b
4
+ data.tar.gz: 81e3205c167c100991cbb2cf80a3528e6b4c471cfa63fa652d56572d5e981867
5
5
  SHA512:
6
- metadata.gz: aaf7872401a767653abe756bc53955e2daa7df56cc1c37a204feff1f409290b0b11ea6cd9afc6e2376992e7be594f6d7c63add7f47e5ebee042fa9092f2dda1a
7
- data.tar.gz: aff10d7f87d429fe6e6e3c14a1697d2641eaf7a2cd427475c79d6f803bcbca64a47861d8e0f93de79e26ed8c44fa9267b981cd5e5b83a4cf40ae3dd0c92b47bf
6
+ metadata.gz: f222b38e5900633eb6b2925a33e58d15425848183501b8ff5ab22010ad8fcd68ab2429dbf4de6302dae3155f49026330aa6c41c95fc52b777e13e257045cb7e8
7
+ data.tar.gz: 85f20d93e24af7b65ffb9371605e18d8729c0b4e2e34d1ad7283bc51beed78016e924a77a55a081d19e90af8c8e81b38d3a010b243de67547337947a1aa88c53
data/CHANGELOG.md CHANGED
@@ -1,7 +1,13 @@
1
1
  CHANGELOG
2
2
  ---------
3
3
 
4
- - **Unreleased - [View Diff](https://github.com/westonganger/active_sort_order/compare/v0.9.2...master)**
4
+ - **Unreleased - [View Diff](https://github.com/westonganger/active_sort_order/compare/v0.9.4...master)**
5
+ * Nothing yet
6
+
7
+ - **v0.9.4 - [View Diff](https://github.com/westonganger/active_sort_order/compare/v0.9.3...v0.9.4)**
8
+ * Improve error handling for sort_col_sql argument
9
+
10
+ - **v0.9.3 - [View Diff](https://github.com/westonganger/active_sort_order/compare/v0.9.2...v0.9.3)**
5
11
  * Allow ability to sort on multiple fields
6
12
 
7
13
  - **v0.9.2 - Apr 28, 2021 - [View Diff](https://github.com/westonganger/active_sort_order/compare/v0.9.1...v0.9.2)**
@@ -5,13 +5,19 @@ module ActiveSortOrder
5
5
  included do
6
6
 
7
7
  scope :sort_order, ->(sort_col_sql = nil, sort_direction_sql = nil, base_sort_order: true){
8
- if sort_col_sql.present?
9
- if sort_col_sql.is_a?(Array)
10
- sort_col_sql = sort_col_sql.map{|x| x.to_s }
8
+ if !sort_col_sql.is_a?(Array)
9
+ sort_col_sql = [sort_col_sql].compact
10
+ end
11
+
12
+ sort_col_sql.each_with_index do |x, i|
13
+ if [String, Symbol].exclude?(x.class)
14
+ raise ArgumentError.new("Invalid first argument `sort_col_sql`, expecting a String or Symbol or Array")
11
15
  else
12
- sort_col_sql = sort_col_sql.to_s
16
+ sort_col_sql[i] = x.to_s
13
17
  end
18
+ end
14
19
 
20
+ if sort_col_sql.present?
15
21
  ### SORT DIRECTION HANDLING
16
22
  if sort_direction_sql.is_a?(Symbol)
17
23
  sort_direction_sql = sort_direction_sql.to_s.gsub('_', ' ')
@@ -41,10 +47,6 @@ module ActiveSortOrder
41
47
  end
42
48
  end
43
49
 
44
- if !sort_col_sql.is_a?(Array)
45
- sort_col_sql = [sort_col_sql]
46
- end
47
-
48
50
  sql_str = sort_col_sql.map{|x| "#{x} #{sort_direction_sql}" }.join(", ")
49
51
  end
50
52
 
@@ -1,3 +1,3 @@
1
1
  module ActiveSortOrder
2
- VERSION = "0.9.3".freeze
2
+ VERSION = "0.9.4".freeze
3
3
  end
Binary file
@@ -540,3 +540,215 @@ ActiveSortOrderTest: test_override_base_sort_order_only
540
540
  ActiveSortOrderTest: test_exposes_main_module
541
541
  ---------------------------------------------
542
542
  TRANSACTION (0.0ms) rollback transaction
543
+  (1.0ms) SELECT sqlite_version(*)
544
+  (0.1ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = ? [["key", "schema_sha1"]]
545
+  (0.0ms) SELECT sqlite_version(*)
546
+  (0.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
547
+  (0.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
548
+ ActiveRecord::InternalMetadata Load (0.1ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = ? LIMIT ? [["key", "environment"], ["LIMIT", 1]]
549
+  (0.9ms) DELETE FROM posts;
550
+  (0.7ms) UPDATE `sqlite_sequence` SET `seq` = 0 WHERE `name` = 'posts';
551
+ Post Load (0.1ms) SELECT "posts".* FROM "posts" WHERE "posts"."a" = ? AND "posts"."b" = ? LIMIT ? [["a", 1], ["b", 3], ["LIMIT", 1]]
552
+ TRANSACTION (0.0ms) begin transaction
553
+ Post Create (0.2ms) INSERT INTO "posts" ("a", "b") VALUES (?, ?) [["a", 1], ["b", 3]]
554
+ TRANSACTION (0.6ms) commit transaction
555
+ Post Load (0.1ms) SELECT "posts".* FROM "posts" WHERE "posts"."a" = ? AND "posts"."b" = ? LIMIT ? [["a", 2], ["b", 2], ["LIMIT", 1]]
556
+ TRANSACTION (0.0ms) begin transaction
557
+ Post Create (0.2ms) INSERT INTO "posts" ("a", "b") VALUES (?, ?) [["a", 2], ["b", 2]]
558
+ TRANSACTION (0.6ms) commit transaction
559
+ Post Load (0.1ms) SELECT "posts".* FROM "posts" WHERE "posts"."a" = ? AND "posts"."b" = ? LIMIT ? [["a", 3], ["b", 2], ["LIMIT", 1]]
560
+ TRANSACTION (0.0ms) begin transaction
561
+ Post Create (0.2ms) INSERT INTO "posts" ("a", "b") VALUES (?, ?) [["a", 3], ["b", 2]]
562
+ TRANSACTION (0.5ms) commit transaction
563
+ Post Load (0.1ms) SELECT "posts".* FROM "posts" WHERE "posts"."a" = ? AND "posts"."b" = ? LIMIT ? [["a", 4], ["b", 1], ["LIMIT", 1]]
564
+ TRANSACTION (0.0ms) begin transaction
565
+ Post Create (0.2ms) INSERT INTO "posts" ("a", "b") VALUES (?, ?) [["a", 4], ["b", 1]]
566
+ TRANSACTION (0.6ms) commit transaction
567
+ Post Load (0.1ms) SELECT "posts".* FROM "posts" WHERE "posts"."a" = ? AND "posts"."b" = ? LIMIT ? [["a", 5], ["b", 1], ["LIMIT", 1]]
568
+ TRANSACTION (0.0ms) begin transaction
569
+ Post Create (0.2ms) INSERT INTO "posts" ("a", "b") VALUES (?, ?) [["a", 5], ["b", 1]]
570
+ TRANSACTION (0.5ms) commit transaction
571
+ TRANSACTION (0.0ms) begin transaction
572
+ -----------------------------------------------
573
+ ActiveSortOrderTest: test_sort_direction_errors
574
+ -----------------------------------------------
575
+ TRANSACTION (0.0ms) rollback transaction
576
+ TRANSACTION (0.0ms) begin transaction
577
+ -------------------------------------------------
578
+ ActiveSortOrderTest: test_sort_on_multiple_fields
579
+ -------------------------------------------------
580
+  (0.1ms) SELECT COUNT(*) FROM "posts"
581
+ PostWithBaseOrderA Load (0.1ms) SELECT "posts".* FROM "posts" ORDER BY b asc, a asc, posts.a ASC
582
+ PostWithBaseOrderA Load (0.1ms) SELECT "posts".* FROM "posts" ORDER BY b desc, a desc, posts.a ASC
583
+ TRANSACTION (0.0ms) rollback transaction
584
+ TRANSACTION (0.0ms) begin transaction
585
+ ---------------------------------------------
586
+ ActiveSortOrderTest: test_exposes_main_module
587
+ ---------------------------------------------
588
+ TRANSACTION (0.0ms) rollback transaction
589
+ TRANSACTION (0.0ms) begin transaction
590
+ ----------------------------------------------------
591
+ ActiveSortOrderTest: test_class_base_sort_order_only
592
+ ----------------------------------------------------
593
+  (0.1ms) SELECT COUNT(*) FROM "posts"
594
+ PostWithBaseOrderA Load (0.1ms) SELECT "posts".* FROM "posts" ORDER BY posts.a ASC
595
+ PostWithBaseOrderB Load (0.1ms) SELECT "posts".* FROM "posts" ORDER BY posts.b ASC
596
+ PostWithBaseOrderAAndB Load (0.1ms) SELECT "posts".* FROM "posts" ORDER BY posts.a ASC, posts.b ASC
597
+ PostWithBaseOrderBAndA Load (0.1ms) SELECT "posts".* FROM "posts" ORDER BY posts.b ASC, posts.a ASC
598
+ TRANSACTION (0.0ms) rollback transaction
599
+ TRANSACTION (0.0ms) begin transaction
600
+ -------------------------------------------------------------
601
+ ActiveSortOrderTest: test_class_method_base_sort_order_errors
602
+ -------------------------------------------------------------
603
+ TRANSACTION (0.1ms) rollback transaction
604
+ TRANSACTION (0.0ms) begin transaction
605
+ -------------------------------------------------------
606
+ ActiveSortOrderTest: test_override_base_sort_order_only
607
+ -------------------------------------------------------
608
+  (0.1ms) SELECT COUNT(*) FROM "posts"
609
+ PostWithBaseOrderA Load (0.1ms) SELECT "posts".* FROM "posts" ORDER BY posts.b ASC
610
+ PostWithBaseOrderA Load (0.0ms) SELECT "posts".* FROM "posts" ORDER BY "posts"."id" ASC
611
+ PostWithBaseOrderA Load (0.0ms) SELECT "posts".* FROM "posts" ORDER BY "posts"."id" ASC
612
+ TRANSACTION (0.0ms) rollback transaction
613
+ TRANSACTION (0.0ms) begin transaction
614
+ -------------------------------------------------------
615
+ ActiveSortOrderTest: test_base_sort_order_default_value
616
+ -------------------------------------------------------
617
+ TRANSACTION (0.0ms) rollback transaction
618
+ TRANSACTION (0.0ms) begin transaction
619
+ ---------------------------------------------------------
620
+ ActiveSortOrderTest: test_argument_base_sort_order_errors
621
+ ---------------------------------------------------------
622
+ TRANSACTION (0.1ms) rollback transaction
623
+ TRANSACTION (0.0ms) begin transaction
624
+ -----------------------------------------
625
+ ActiveSortOrderTest: test_exposes_version
626
+ -----------------------------------------
627
+ TRANSACTION (0.0ms) rollback transaction
628
+ TRANSACTION (0.0ms) begin transaction
629
+ --------------------------------------------------
630
+ ActiveSortOrderTest: test_base_sort_order_and_sort
631
+ --------------------------------------------------
632
+  (0.1ms) SELECT COUNT(*) FROM "posts"
633
+ PostWithBaseOrderA Load (0.1ms) SELECT "posts".* FROM "posts" ORDER BY posts.a DESC, posts.a ASC
634
+ PostWithBaseOrderB Load (0.1ms) SELECT "posts".* FROM "posts" ORDER BY posts.b DESC, posts.b ASC
635
+ TRANSACTION (0.0ms) rollback transaction
636
+ TRANSACTION (0.0ms) begin transaction
637
+ -----------------------------------------
638
+ ActiveSortOrderTest: test_sort_str_errors
639
+ -----------------------------------------
640
+ TRANSACTION (0.0ms) rollback transaction
641
+ TRANSACTION (0.0ms) begin transaction
642
+ -----------------------------------
643
+ ActiveSortOrderTest: test_sort_only
644
+ -----------------------------------
645
+  (0.1ms) SELECT COUNT(*) FROM "posts"
646
+ PostWithBaseOrderA Load (0.1ms) SELECT "posts".* FROM "posts" ORDER BY a desc, posts.a ASC
647
+ PostWithBaseOrderA Load (0.1ms) SELECT "posts".* FROM "posts" ORDER BY posts.a DESC, posts.a ASC
648
+ TRANSACTION (0.0ms) rollback transaction
649
+  (0.7ms) SELECT sqlite_version(*)
650
+  (0.1ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = ? [["key", "schema_sha1"]]
651
+  (0.1ms) SELECT sqlite_version(*)
652
+  (0.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
653
+  (0.0ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
654
+ ActiveRecord::InternalMetadata Load (0.1ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = ? LIMIT ? [["key", "environment"], ["LIMIT", 1]]
655
+  (1.3ms) DELETE FROM posts;
656
+  (1.0ms) UPDATE `sqlite_sequence` SET `seq` = 0 WHERE `name` = 'posts';
657
+ Post Load (0.1ms) SELECT "posts".* FROM "posts" WHERE "posts"."a" = ? AND "posts"."b" = ? LIMIT ? [["a", 1], ["b", 3], ["LIMIT", 1]]
658
+ TRANSACTION (0.0ms) begin transaction
659
+ Post Create (0.2ms) INSERT INTO "posts" ("a", "b") VALUES (?, ?) [["a", 1], ["b", 3]]
660
+ TRANSACTION (0.6ms) commit transaction
661
+ Post Load (0.1ms) SELECT "posts".* FROM "posts" WHERE "posts"."a" = ? AND "posts"."b" = ? LIMIT ? [["a", 2], ["b", 2], ["LIMIT", 1]]
662
+ TRANSACTION (0.0ms) begin transaction
663
+ Post Create (0.2ms) INSERT INTO "posts" ("a", "b") VALUES (?, ?) [["a", 2], ["b", 2]]
664
+ TRANSACTION (0.7ms) commit transaction
665
+ Post Load (0.1ms) SELECT "posts".* FROM "posts" WHERE "posts"."a" = ? AND "posts"."b" = ? LIMIT ? [["a", 3], ["b", 2], ["LIMIT", 1]]
666
+ TRANSACTION (0.0ms) begin transaction
667
+ Post Create (0.2ms) INSERT INTO "posts" ("a", "b") VALUES (?, ?) [["a", 3], ["b", 2]]
668
+ TRANSACTION (0.7ms) commit transaction
669
+ Post Load (0.1ms) SELECT "posts".* FROM "posts" WHERE "posts"."a" = ? AND "posts"."b" = ? LIMIT ? [["a", 4], ["b", 1], ["LIMIT", 1]]
670
+ TRANSACTION (0.0ms) begin transaction
671
+ Post Create (0.2ms) INSERT INTO "posts" ("a", "b") VALUES (?, ?) [["a", 4], ["b", 1]]
672
+ TRANSACTION (0.6ms) commit transaction
673
+ Post Load (0.1ms) SELECT "posts".* FROM "posts" WHERE "posts"."a" = ? AND "posts"."b" = ? LIMIT ? [["a", 5], ["b", 1], ["LIMIT", 1]]
674
+ TRANSACTION (0.0ms) begin transaction
675
+ Post Create (0.2ms) INSERT INTO "posts" ("a", "b") VALUES (?, ?) [["a", 5], ["b", 1]]
676
+ TRANSACTION (0.7ms) commit transaction
677
+ TRANSACTION (0.0ms) begin transaction
678
+ --------------------------------------------------
679
+ ActiveSortOrderTest: test_base_sort_order_and_sort
680
+ --------------------------------------------------
681
+  (0.1ms) SELECT COUNT(*) FROM "posts"
682
+ PostWithBaseOrderA Load (0.1ms) SELECT "posts".* FROM "posts" ORDER BY posts.a DESC, posts.a ASC
683
+ PostWithBaseOrderB Load (0.1ms) SELECT "posts".* FROM "posts" ORDER BY posts.b DESC, posts.b ASC
684
+ TRANSACTION (0.0ms) rollback transaction
685
+ TRANSACTION (0.0ms) begin transaction
686
+ -------------------------------------------------------------
687
+ ActiveSortOrderTest: test_class_method_base_sort_order_errors
688
+ -------------------------------------------------------------
689
+ TRANSACTION (0.0ms) rollback transaction
690
+ TRANSACTION (0.0ms) begin transaction
691
+ -----------------------------------
692
+ ActiveSortOrderTest: test_sort_only
693
+ -----------------------------------
694
+  (0.1ms) SELECT COUNT(*) FROM "posts"
695
+ PostWithBaseOrderA Load (0.1ms) SELECT "posts".* FROM "posts" ORDER BY a desc, posts.a ASC
696
+ PostWithBaseOrderA Load (0.1ms) SELECT "posts".* FROM "posts" ORDER BY posts.a DESC, posts.a ASC
697
+ TRANSACTION (0.0ms) rollback transaction
698
+ TRANSACTION (0.0ms) begin transaction
699
+ -----------------------------------------
700
+ ActiveSortOrderTest: test_exposes_version
701
+ -----------------------------------------
702
+ TRANSACTION (0.0ms) rollback transaction
703
+ TRANSACTION (0.0ms) begin transaction
704
+ -----------------------------------------------
705
+ ActiveSortOrderTest: test_sort_direction_errors
706
+ -----------------------------------------------
707
+ TRANSACTION (0.0ms) rollback transaction
708
+ TRANSACTION (0.0ms) begin transaction
709
+ ---------------------------------------------------------
710
+ ActiveSortOrderTest: test_argument_base_sort_order_errors
711
+ ---------------------------------------------------------
712
+ TRANSACTION (0.0ms) rollback transaction
713
+ TRANSACTION (0.0ms) begin transaction
714
+ -------------------------------------------------------
715
+ ActiveSortOrderTest: test_override_base_sort_order_only
716
+ -------------------------------------------------------
717
+  (0.1ms) SELECT COUNT(*) FROM "posts"
718
+ PostWithBaseOrderA Load (0.1ms) SELECT "posts".* FROM "posts" ORDER BY posts.b ASC
719
+ PostWithBaseOrderA Load (0.0ms) SELECT "posts".* FROM "posts" ORDER BY "posts"."id" ASC
720
+ PostWithBaseOrderA Load (0.0ms) SELECT "posts".* FROM "posts" ORDER BY "posts"."id" ASC
721
+ TRANSACTION (0.0ms) rollback transaction
722
+ TRANSACTION (0.0ms) begin transaction
723
+ -------------------------------------------------
724
+ ActiveSortOrderTest: test_sort_on_multiple_fields
725
+ -------------------------------------------------
726
+  (0.1ms) SELECT COUNT(*) FROM "posts"
727
+ PostWithBaseOrderA Load (0.1ms) SELECT "posts".* FROM "posts" ORDER BY b asc, a asc, posts.a ASC
728
+ PostWithBaseOrderA Load (0.1ms) SELECT "posts".* FROM "posts" ORDER BY b desc, a desc, posts.a ASC
729
+ TRANSACTION (0.0ms) rollback transaction
730
+ TRANSACTION (0.0ms) begin transaction
731
+ -----------------------------------------
732
+ ActiveSortOrderTest: test_sort_str_errors
733
+ -----------------------------------------
734
+ TRANSACTION (0.0ms) rollback transaction
735
+ TRANSACTION (0.0ms) begin transaction
736
+ ---------------------------------------------
737
+ ActiveSortOrderTest: test_exposes_main_module
738
+ ---------------------------------------------
739
+ TRANSACTION (0.0ms) rollback transaction
740
+ TRANSACTION (0.0ms) begin transaction
741
+ -------------------------------------------------------
742
+ ActiveSortOrderTest: test_base_sort_order_default_value
743
+ -------------------------------------------------------
744
+ TRANSACTION (0.3ms) rollback transaction
745
+ TRANSACTION (0.2ms) begin transaction
746
+ ----------------------------------------------------
747
+ ActiveSortOrderTest: test_class_base_sort_order_only
748
+ ----------------------------------------------------
749
+  (0.7ms) SELECT COUNT(*) FROM "posts"
750
+ PostWithBaseOrderA Load (0.4ms) SELECT "posts".* FROM "posts" ORDER BY posts.a ASC
751
+ PostWithBaseOrderB Load (0.4ms) SELECT "posts".* FROM "posts" ORDER BY posts.b ASC
752
+ PostWithBaseOrderAAndB Load (0.1ms) SELECT "posts".* FROM "posts" ORDER BY posts.a ASC, posts.b ASC
753
+ PostWithBaseOrderBAndA Load (0.1ms) SELECT "posts".* FROM "posts" ORDER BY posts.b ASC, posts.a ASC
754
+ TRANSACTION (0.1ms) rollback transaction
@@ -15,6 +15,8 @@ class ActiveSortOrderTest < ActiveSupport::TestCase
15
15
  :foo,
16
16
  nil,
17
17
  "",
18
+ [],
19
+ [:foo],
18
20
  ]
19
21
 
20
22
  valid.each do |v|
@@ -25,7 +27,6 @@ class ActiveSortOrderTest < ActiveSupport::TestCase
25
27
  invalid = [
26
28
  true,
27
29
  false,
28
- [],
29
30
  Object.new,
30
31
  ]
31
32
 
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.3
4
+ version: 0.9.4
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-10-14 00:00:00.000000000 Z
11
+ date: 2021-12-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord