has_public_id 1.2.0 → 1.2.1

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: f1bfdbb495ebd35dbba710e54a1257df584866df
4
- data.tar.gz: d3d051f8b14977452ea29855986d5c4cfcf45e3b
3
+ metadata.gz: 2c6f7e2297b06b7dbb118b60faa7e0fdd4bf1400
4
+ data.tar.gz: bd594783a44a5762c9a7477f5bc17149f0ffae3a
5
5
  SHA512:
6
- metadata.gz: 3f41e94856864dc1d828892b7c17da23dbe1dc888d97acf0f36c95bd6a686033e7281f7a43cd35f3332ecdb6678916885e6d7eeb6e28a4673e2f6f95763360e1
7
- data.tar.gz: 7b44432e54df200836978eb51aa1ab48247c94b71e46974c7727fec43b1ce3a8f6939299008595169f37137e6a48732ddbc2b4e2796d6414201cb668d3e9f0bf
6
+ metadata.gz: 851e3c7626f2696dd7c194af8711352c9a64f65070086c835dfada466135650c08df42ecfa114edfedd57e78132fdf71ffaa9a77185f2c509d4ba333a284d09b
7
+ data.tar.gz: 8d8a0d6f329c95f898959a3d87d711e906942fca0826ab49a1c8fe736d6e33528aa724c6edb3083dee232ba7e9bcaf5dc441a0e6689a3771ce21ed32a4bc45b5
@@ -38,6 +38,9 @@ module HasPublicId
38
38
  end
39
39
 
40
40
  def find_by_public_id!(public_id)
41
+ if public_id.blank?
42
+ raise ::ActiveRecord::RecordNotFound.new("Couldn't find #{self.name} without an ID")
43
+ end
41
44
  where(self.public_id_attr => public_id).first or
42
45
  raise ::ActiveRecord::RecordNotFound.new("Couldn't find #{self.name} with #{public_id}")
43
46
  end
@@ -1,3 +1,3 @@
1
1
  module HasPublicId
2
- VERSION = "1.2.0"
2
+ VERSION = "1.2.1"
3
3
  end
Binary file
@@ -482,3 +482,162 @@ UserTest: test_use_group-by_sql
482
482
  User Load (0.1ms) SELECT "users".* FROM "users"
483
483
  User Load (0.1ms) SELECT "users".* FROM "users"
484
484
   (0.1ms) rollback transaction
485
+ ActiveRecord::SchemaMigration Load (2.5ms) SELECT "schema_migrations".* FROM "schema_migrations"
486
+  (3.8ms) CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar, "ident" varchar, "created_at" datetime, "updated_at" datetime) 
487
+  (2.7ms) CREATE TABLE "schema_migrations" ("version" varchar NOT NULL)
488
+  (0.2ms) select sqlite_version(*)
489
+  (8.5ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
490
+  (0.2ms) SELECT version FROM "schema_migrations"
491
+  (6.6ms) INSERT INTO "schema_migrations" (version) VALUES ('20140109180823')
492
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
493
+  (0.2ms) begin transaction
494
+ Fixture Delete (0.7ms) DELETE FROM "users"
495
+ Fixture Insert (0.6ms) INSERT INTO "users" ("name", "ident", "created_at", "updated_at", "id") VALUES ('Sammy', NULL, '2016-02-05 21:49:23', '2016-02-05 21:49:23', 980190962)
496
+ Fixture Insert (0.1ms) INSERT INTO "users" ("name", "ident", "created_at", "updated_at", "id") VALUES ('Joe', NULL, '2016-02-05 21:49:23', '2016-02-05 21:49:23', 298486374)
497
+ Fixture Insert (0.1ms) INSERT INTO "users" ("name", "ident", "created_at", "updated_at", "id") VALUES ('Susan', NULL, '2016-02-05 21:49:23', '2016-02-05 21:49:23', 113629430)
498
+  (3.0ms) commit transaction
499
+  (0.1ms) begin transaction
500
+ ----------------------------------------
501
+ AdminTest: test_identifier_doesnt_change
502
+ ----------------------------------------
503
+  (0.1ms) SAVEPOINT active_record_1
504
+ SQL (0.5ms) INSERT INTO "users" ("ident", "created_at", "updated_at") VALUES (?, ?, ?) [["ident", "user-LH6Sobn1hYds"], ["created_at", "2016-02-05 21:49:23.360170"], ["updated_at", "2016-02-05 21:49:23.360170"]]
505
+  (0.1ms) RELEASE SAVEPOINT active_record_1
506
+ Admin Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 980190963]]
507
+  (0.1ms) SAVEPOINT active_record_1
508
+  (0.0ms) RELEASE SAVEPOINT active_record_1
509
+ Admin Load (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 980190963]]
510
+  (2.3ms) rollback transaction
511
+  (0.1ms) begin transaction
512
+ --------------------------------------------------
513
+ AdminTest: test_identifier_initializes_from_parent
514
+ --------------------------------------------------
515
+  (0.1ms) rollback transaction
516
+  (0.1ms) begin transaction
517
+ --------------------------------------------------
518
+ AdminTest: test_inherited_class_has_public_id_attr
519
+ --------------------------------------------------
520
+  (0.0ms) rollback transaction
521
+  (0.0ms) begin transaction
522
+ -------------------------------------------
523
+ HasPublicId::UtilTest: test_char_set.length
524
+ -------------------------------------------
525
+  (0.0ms) rollback transaction
526
+  (0.0ms) begin transaction
527
+ --------------------------------------------------
528
+ HasPublicId::UtilTest: test_generate_random_suffix
529
+ --------------------------------------------------
530
+  (0.1ms) rollback transaction
531
+  (0.1ms) begin transaction
532
+ ----------------------------------------------------------
533
+ HasPublicId::UtilTest: test_generate_random_suffix(length)
534
+ ----------------------------------------------------------
535
+  (0.0ms) rollback transaction
536
+  (0.0ms) begin transaction
537
+ ------------------------------------------------------------
538
+ HasPublicId::UtilTest: test_new_public_id(with_blank_prefix)
539
+ ------------------------------------------------------------
540
+  (0.0ms) rollback transaction
541
+  (0.0ms) begin transaction
542
+ ------------------------------------------------------------
543
+ HasPublicId::UtilTest: test_new_public_id(with_false_prefix)
544
+ ------------------------------------------------------------
545
+  (0.0ms) rollback transaction
546
+  (0.0ms) begin transaction
547
+ ---------------------------------------------------------
548
+ HasPublicId::UtilTest: test_new_public_id(with_join_with)
549
+ ---------------------------------------------------------
550
+  (0.0ms) rollback transaction
551
+  (0.0ms) begin transaction
552
+ ----------------------------------------------------------
553
+ HasPublicId::UtilTest: test_new_public_id(with_nil_prefix)
554
+ ----------------------------------------------------------
555
+  (0.0ms) rollback transaction
556
+  (0.1ms) begin transaction
557
+ ------------------------------------------------------
558
+ HasPublicId::UtilTest: test_new_public_id(with_prefix)
559
+ ------------------------------------------------------
560
+  (0.0ms) rollback transaction
561
+  (0.0ms) begin transaction
562
+ ---------------------------
563
+ HasPublicIdTest: test_Mixin
564
+ ---------------------------
565
+  (0.0ms) rollback transaction
566
+  (0.1ms) begin transaction
567
+ Fixture Delete (0.3ms) DELETE FROM "users"
568
+ Fixture Insert (0.1ms) INSERT INTO "users" ("name", "ident", "created_at", "updated_at", "id") VALUES ('Sammy', NULL, '2016-02-05 21:49:23', '2016-02-05 21:49:23', 980190962)
569
+ Fixture Insert (0.1ms) INSERT INTO "users" ("name", "ident", "created_at", "updated_at", "id") VALUES ('Joe', NULL, '2016-02-05 21:49:23', '2016-02-05 21:49:23', 298486374)
570
+ Fixture Insert (0.1ms) INSERT INTO "users" ("name", "ident", "created_at", "updated_at", "id") VALUES ('Susan', NULL, '2016-02-05 21:49:23', '2016-02-05 21:49:23', 113629430)
571
+  (2.7ms) commit transaction
572
+  (0.1ms) begin transaction
573
+ --------------------------------
574
+ UserTest: test_find_by_public_id
575
+ --------------------------------
576
+  (0.0ms) SAVEPOINT active_record_1
577
+ SQL (0.2ms) INSERT INTO "users" ("name", "ident", "created_at", "updated_at") VALUES (?, ?, ?, ?) [["name", "joey"], ["ident", "user-Fq4ANV6QbsR6"], ["created_at", "2016-02-05 21:49:23.470557"], ["updated_at", "2016-02-05 21:49:23.470557"]]
578
+  (0.0ms) RELEASE SAVEPOINT active_record_1
579
+ User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."ident" = ? ORDER BY "users"."id" ASC LIMIT 1 [["ident", "user-Fq4ANV6QbsR6"]]
580
+ User Load (0.0ms) SELECT "users".* FROM "users" WHERE "users"."ident" = ? ORDER BY "users"."id" ASC LIMIT 1 [["ident", "bad_key"]]
581
+  (2.2ms) rollback transaction
582
+  (0.1ms) begin transaction
583
+ ---------------------------------
584
+ UserTest: test_find_by_public_id!
585
+ ---------------------------------
586
+  (0.1ms) SAVEPOINT active_record_1
587
+ SQL (0.3ms) INSERT INTO "users" ("name", "ident", "created_at", "updated_at") VALUES (?, ?, ?, ?) [["name", "joey"], ["ident", "user-dao36sMDjrAd"], ["created_at", "2016-02-05 21:49:23.476339"], ["updated_at", "2016-02-05 21:49:23.476339"]]
588
+  (0.1ms) RELEASE SAVEPOINT active_record_1
589
+ User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."ident" = ? ORDER BY "users"."id" ASC LIMIT 1 [["ident", "user-dao36sMDjrAd"]]
590
+ User Load (0.0ms) SELECT "users".* FROM "users" WHERE "users"."ident" = ? ORDER BY "users"."id" ASC LIMIT 1 [["ident", "bad_key"]]
591
+  (2.2ms) rollback transaction
592
+  (0.1ms) begin transaction
593
+ ---------------------------------------
594
+ UserTest: test_identifier_doesnt_change
595
+ ---------------------------------------
596
+  (0.0ms) SAVEPOINT active_record_1
597
+ SQL (0.2ms) INSERT INTO "users" ("ident", "created_at", "updated_at") VALUES (?, ?, ?) [["ident", "user-nayg4RJOocRW"], ["created_at", "2016-02-05 21:49:23.482573"], ["updated_at", "2016-02-05 21:49:23.482573"]]
598
+  (0.0ms) RELEASE SAVEPOINT active_record_1
599
+ User Load (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 980190963]]
600
+  (0.0ms) SAVEPOINT active_record_1
601
+  (0.0ms) RELEASE SAVEPOINT active_record_1
602
+ User Load (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 980190963]]
603
+  (2.2ms) rollback transaction
604
+  (0.1ms) begin transaction
605
+ -------------------------------------
606
+ UserTest: test_identifier_initializes
607
+ -------------------------------------
608
+  (0.1ms) rollback transaction
609
+  (0.1ms) begin transaction
610
+ -------------------------------------
611
+ UserTest: test_initialize_public_ids!
612
+ -------------------------------------
613
+  (0.2ms) SELECT COUNT(*) FROM "users" WHERE "users"."ident" IS NULL
614
+ User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."ident" IS NULL ORDER BY "users"."id" ASC LIMIT 1000
615
+  (0.1ms) SAVEPOINT active_record_1
616
+ SQL (0.4ms) UPDATE "users" SET "ident" = ?, "updated_at" = ? WHERE "users"."id" = ? [["ident", "user-oLVkWf91KCxJ"], ["updated_at", "2016-02-05 21:49:23.492904"], ["id", 113629430]]
617
+  (0.1ms) RELEASE SAVEPOINT active_record_1
618
+  (0.0ms) SAVEPOINT active_record_1
619
+ SQL (0.9ms) UPDATE "users" SET "ident" = ?, "updated_at" = ? WHERE "users"."id" = ? [["ident", "user-2iZlSjEc0HaP"], ["updated_at", "2016-02-05 21:49:23.495449"], ["id", 298486374]]
620
+  (0.0ms) RELEASE SAVEPOINT active_record_1
621
+  (0.0ms) SAVEPOINT active_record_1
622
+ SQL (0.0ms) UPDATE "users" SET "ident" = ?, "updated_at" = ? WHERE "users"."id" = ? [["ident", "user-SgF6oYQjYhMc"], ["updated_at", "2016-02-05 21:49:23.497431"], ["id", 980190962]]
623
+  (0.0ms) RELEASE SAVEPOINT active_record_1
624
+  (0.1ms) SELECT COUNT(*) FROM "users" WHERE "users"."ident" IS NULL
625
+  (2.4ms) rollback transaction
626
+  (0.1ms) begin transaction
627
+ ----------------------------
628
+ UserTest: test_new_public_id
629
+ ----------------------------
630
+  (0.1ms) rollback transaction
631
+  (0.2ms) begin transaction
632
+ ------------------------------------------
633
+ UserTest: test_to_param_matches_identifier
634
+ ------------------------------------------
635
+  (0.1ms) rollback transaction
636
+  (0.1ms) begin transaction
637
+ -------------------------------
638
+ UserTest: test_use_group-by_sql
639
+ -------------------------------
640
+ User Load (0.2ms) SELECT name, count(name) as count FROM "users" GROUP BY "users"."name"
641
+ User Load (0.1ms) SELECT "users".* FROM "users"
642
+ User Load (0.1ms) SELECT "users".* FROM "users"
643
+  (0.0ms) rollback transaction
@@ -41,6 +41,7 @@ class UserTest < ActiveSupport::TestCase
41
41
  u = User.create(name: 'joey')
42
42
  assert_equal u, User.find_by_public_id!(u.to_param), "Can't be looked up by #{u.to_param}"
43
43
  assert_raises(ActiveRecord::RecordNotFound){ User.find_by_public_id!('bad_key') }
44
+ assert_raises(ActiveRecord::RecordNotFound){ User.find_by_public_id!(nil) }
44
45
  end
45
46
 
46
47
  test "initialize_public_ids!" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: has_public_id
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Graham Melcher