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 +4 -4
- data/lib/has_public_id/activerecord/mixin.rb +3 -0
- data/lib/has_public_id/version.rb +1 -1
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/test.log +159 -0
- data/test/dummy/test/models/user_test.rb +1 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2c6f7e2297b06b7dbb118b60faa7e0fdd4bf1400
|
4
|
+
data.tar.gz: bd594783a44a5762c9a7477f5bc17149f0ffae3a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
data/test/dummy/db/test.sqlite3
CHANGED
Binary file
|
data/test/dummy/log/test.log
CHANGED
@@ -482,3 +482,162 @@ UserTest: test_use_group-by_sql
|
|
482
482
|
[1m[36mUser Load (0.1ms)[0m [1mSELECT "users".* FROM "users"[0m
|
483
483
|
[1m[35mUser Load (0.1ms)[0m SELECT "users".* FROM "users"
|
484
484
|
[1m[36m (0.1ms)[0m [1mrollback transaction[0m
|
485
|
+
[1m[36mActiveRecord::SchemaMigration Load (2.5ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
486
|
+
[1m[36m (3.8ms)[0m [1mCREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar, "ident" varchar, "created_at" datetime, "updated_at" datetime) [0m
|
487
|
+
[1m[35m (2.7ms)[0m CREATE TABLE "schema_migrations" ("version" varchar NOT NULL)
|
488
|
+
[1m[36m (0.2ms)[0m [1mselect sqlite_version(*)[0m
|
489
|
+
[1m[35m (8.5ms)[0m CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
|
490
|
+
[1m[36m (0.2ms)[0m [1mSELECT version FROM "schema_migrations"[0m
|
491
|
+
[1m[35m (6.6ms)[0m INSERT INTO "schema_migrations" (version) VALUES ('20140109180823')
|
492
|
+
[1m[35mActiveRecord::SchemaMigration Load (0.1ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|
493
|
+
[1m[36m (0.2ms)[0m [1mbegin transaction[0m
|
494
|
+
[1m[35mFixture Delete (0.7ms)[0m DELETE FROM "users"
|
495
|
+
[1m[36mFixture Insert (0.6ms)[0m [1mINSERT 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)[0m
|
496
|
+
[1m[35mFixture Insert (0.1ms)[0m 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
|
+
[1m[36mFixture Insert (0.1ms)[0m [1mINSERT 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)[0m
|
498
|
+
[1m[35m (3.0ms)[0m commit transaction
|
499
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
500
|
+
----------------------------------------
|
501
|
+
AdminTest: test_identifier_doesnt_change
|
502
|
+
----------------------------------------
|
503
|
+
[1m[35m (0.1ms)[0m SAVEPOINT active_record_1
|
504
|
+
[1m[36mSQL (0.5ms)[0m [1mINSERT INTO "users" ("ident", "created_at", "updated_at") VALUES (?, ?, ?)[0m [["ident", "user-LH6Sobn1hYds"], ["created_at", "2016-02-05 21:49:23.360170"], ["updated_at", "2016-02-05 21:49:23.360170"]]
|
505
|
+
[1m[35m (0.1ms)[0m RELEASE SAVEPOINT active_record_1
|
506
|
+
[1m[36mAdmin Load (0.2ms)[0m [1mSELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1[0m [["id", 980190963]]
|
507
|
+
[1m[35m (0.1ms)[0m SAVEPOINT active_record_1
|
508
|
+
[1m[36m (0.0ms)[0m [1mRELEASE SAVEPOINT active_record_1[0m
|
509
|
+
[1m[35mAdmin Load (0.0ms)[0m SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 980190963]]
|
510
|
+
[1m[36m (2.3ms)[0m [1mrollback transaction[0m
|
511
|
+
[1m[35m (0.1ms)[0m begin transaction
|
512
|
+
--------------------------------------------------
|
513
|
+
AdminTest: test_identifier_initializes_from_parent
|
514
|
+
--------------------------------------------------
|
515
|
+
[1m[36m (0.1ms)[0m [1mrollback transaction[0m
|
516
|
+
[1m[35m (0.1ms)[0m begin transaction
|
517
|
+
--------------------------------------------------
|
518
|
+
AdminTest: test_inherited_class_has_public_id_attr
|
519
|
+
--------------------------------------------------
|
520
|
+
[1m[36m (0.0ms)[0m [1mrollback transaction[0m
|
521
|
+
[1m[35m (0.0ms)[0m begin transaction
|
522
|
+
-------------------------------------------
|
523
|
+
HasPublicId::UtilTest: test_char_set.length
|
524
|
+
-------------------------------------------
|
525
|
+
[1m[36m (0.0ms)[0m [1mrollback transaction[0m
|
526
|
+
[1m[35m (0.0ms)[0m begin transaction
|
527
|
+
--------------------------------------------------
|
528
|
+
HasPublicId::UtilTest: test_generate_random_suffix
|
529
|
+
--------------------------------------------------
|
530
|
+
[1m[36m (0.1ms)[0m [1mrollback transaction[0m
|
531
|
+
[1m[35m (0.1ms)[0m begin transaction
|
532
|
+
----------------------------------------------------------
|
533
|
+
HasPublicId::UtilTest: test_generate_random_suffix(length)
|
534
|
+
----------------------------------------------------------
|
535
|
+
[1m[36m (0.0ms)[0m [1mrollback transaction[0m
|
536
|
+
[1m[35m (0.0ms)[0m begin transaction
|
537
|
+
------------------------------------------------------------
|
538
|
+
HasPublicId::UtilTest: test_new_public_id(with_blank_prefix)
|
539
|
+
------------------------------------------------------------
|
540
|
+
[1m[36m (0.0ms)[0m [1mrollback transaction[0m
|
541
|
+
[1m[35m (0.0ms)[0m begin transaction
|
542
|
+
------------------------------------------------------------
|
543
|
+
HasPublicId::UtilTest: test_new_public_id(with_false_prefix)
|
544
|
+
------------------------------------------------------------
|
545
|
+
[1m[36m (0.0ms)[0m [1mrollback transaction[0m
|
546
|
+
[1m[35m (0.0ms)[0m begin transaction
|
547
|
+
---------------------------------------------------------
|
548
|
+
HasPublicId::UtilTest: test_new_public_id(with_join_with)
|
549
|
+
---------------------------------------------------------
|
550
|
+
[1m[36m (0.0ms)[0m [1mrollback transaction[0m
|
551
|
+
[1m[35m (0.0ms)[0m begin transaction
|
552
|
+
----------------------------------------------------------
|
553
|
+
HasPublicId::UtilTest: test_new_public_id(with_nil_prefix)
|
554
|
+
----------------------------------------------------------
|
555
|
+
[1m[36m (0.0ms)[0m [1mrollback transaction[0m
|
556
|
+
[1m[35m (0.1ms)[0m begin transaction
|
557
|
+
------------------------------------------------------
|
558
|
+
HasPublicId::UtilTest: test_new_public_id(with_prefix)
|
559
|
+
------------------------------------------------------
|
560
|
+
[1m[36m (0.0ms)[0m [1mrollback transaction[0m
|
561
|
+
[1m[35m (0.0ms)[0m begin transaction
|
562
|
+
---------------------------
|
563
|
+
HasPublicIdTest: test_Mixin
|
564
|
+
---------------------------
|
565
|
+
[1m[36m (0.0ms)[0m [1mrollback transaction[0m
|
566
|
+
[1m[35m (0.1ms)[0m begin transaction
|
567
|
+
[1m[36mFixture Delete (0.3ms)[0m [1mDELETE FROM "users"[0m
|
568
|
+
[1m[35mFixture Insert (0.1ms)[0m 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
|
+
[1m[36mFixture Insert (0.1ms)[0m [1mINSERT 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)[0m
|
570
|
+
[1m[35mFixture Insert (0.1ms)[0m 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
|
+
[1m[36m (2.7ms)[0m [1mcommit transaction[0m
|
572
|
+
[1m[35m (0.1ms)[0m begin transaction
|
573
|
+
--------------------------------
|
574
|
+
UserTest: test_find_by_public_id
|
575
|
+
--------------------------------
|
576
|
+
[1m[36m (0.0ms)[0m [1mSAVEPOINT active_record_1[0m
|
577
|
+
[1m[35mSQL (0.2ms)[0m 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
|
+
[1m[36m (0.0ms)[0m [1mRELEASE SAVEPOINT active_record_1[0m
|
579
|
+
[1m[35mUser Load (0.1ms)[0m SELECT "users".* FROM "users" WHERE "users"."ident" = ? ORDER BY "users"."id" ASC LIMIT 1 [["ident", "user-Fq4ANV6QbsR6"]]
|
580
|
+
[1m[36mUser Load (0.0ms)[0m [1mSELECT "users".* FROM "users" WHERE "users"."ident" = ? ORDER BY "users"."id" ASC LIMIT 1[0m [["ident", "bad_key"]]
|
581
|
+
[1m[35m (2.2ms)[0m rollback transaction
|
582
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
583
|
+
---------------------------------
|
584
|
+
UserTest: test_find_by_public_id!
|
585
|
+
---------------------------------
|
586
|
+
[1m[35m (0.1ms)[0m SAVEPOINT active_record_1
|
587
|
+
[1m[36mSQL (0.3ms)[0m [1mINSERT INTO "users" ("name", "ident", "created_at", "updated_at") VALUES (?, ?, ?, ?)[0m [["name", "joey"], ["ident", "user-dao36sMDjrAd"], ["created_at", "2016-02-05 21:49:23.476339"], ["updated_at", "2016-02-05 21:49:23.476339"]]
|
588
|
+
[1m[35m (0.1ms)[0m RELEASE SAVEPOINT active_record_1
|
589
|
+
[1m[36mUser Load (0.1ms)[0m [1mSELECT "users".* FROM "users" WHERE "users"."ident" = ? ORDER BY "users"."id" ASC LIMIT 1[0m [["ident", "user-dao36sMDjrAd"]]
|
590
|
+
[1m[35mUser Load (0.0ms)[0m SELECT "users".* FROM "users" WHERE "users"."ident" = ? ORDER BY "users"."id" ASC LIMIT 1 [["ident", "bad_key"]]
|
591
|
+
[1m[36m (2.2ms)[0m [1mrollback transaction[0m
|
592
|
+
[1m[35m (0.1ms)[0m begin transaction
|
593
|
+
---------------------------------------
|
594
|
+
UserTest: test_identifier_doesnt_change
|
595
|
+
---------------------------------------
|
596
|
+
[1m[36m (0.0ms)[0m [1mSAVEPOINT active_record_1[0m
|
597
|
+
[1m[35mSQL (0.2ms)[0m 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
|
+
[1m[36m (0.0ms)[0m [1mRELEASE SAVEPOINT active_record_1[0m
|
599
|
+
[1m[35mUser Load (0.0ms)[0m SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 980190963]]
|
600
|
+
[1m[36m (0.0ms)[0m [1mSAVEPOINT active_record_1[0m
|
601
|
+
[1m[35m (0.0ms)[0m RELEASE SAVEPOINT active_record_1
|
602
|
+
[1m[36mUser Load (0.0ms)[0m [1mSELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1[0m [["id", 980190963]]
|
603
|
+
[1m[35m (2.2ms)[0m rollback transaction
|
604
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
605
|
+
-------------------------------------
|
606
|
+
UserTest: test_identifier_initializes
|
607
|
+
-------------------------------------
|
608
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
609
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
610
|
+
-------------------------------------
|
611
|
+
UserTest: test_initialize_public_ids!
|
612
|
+
-------------------------------------
|
613
|
+
[1m[35m (0.2ms)[0m SELECT COUNT(*) FROM "users" WHERE "users"."ident" IS NULL
|
614
|
+
[1m[36mUser Load (0.2ms)[0m [1mSELECT "users".* FROM "users" WHERE "users"."ident" IS NULL ORDER BY "users"."id" ASC LIMIT 1000[0m
|
615
|
+
[1m[35m (0.1ms)[0m SAVEPOINT active_record_1
|
616
|
+
[1m[36mSQL (0.4ms)[0m [1mUPDATE "users" SET "ident" = ?, "updated_at" = ? WHERE "users"."id" = ?[0m [["ident", "user-oLVkWf91KCxJ"], ["updated_at", "2016-02-05 21:49:23.492904"], ["id", 113629430]]
|
617
|
+
[1m[35m (0.1ms)[0m RELEASE SAVEPOINT active_record_1
|
618
|
+
[1m[36m (0.0ms)[0m [1mSAVEPOINT active_record_1[0m
|
619
|
+
[1m[35mSQL (0.9ms)[0m UPDATE "users" SET "ident" = ?, "updated_at" = ? WHERE "users"."id" = ? [["ident", "user-2iZlSjEc0HaP"], ["updated_at", "2016-02-05 21:49:23.495449"], ["id", 298486374]]
|
620
|
+
[1m[36m (0.0ms)[0m [1mRELEASE SAVEPOINT active_record_1[0m
|
621
|
+
[1m[35m (0.0ms)[0m SAVEPOINT active_record_1
|
622
|
+
[1m[36mSQL (0.0ms)[0m [1mUPDATE "users" SET "ident" = ?, "updated_at" = ? WHERE "users"."id" = ?[0m [["ident", "user-SgF6oYQjYhMc"], ["updated_at", "2016-02-05 21:49:23.497431"], ["id", 980190962]]
|
623
|
+
[1m[35m (0.0ms)[0m RELEASE SAVEPOINT active_record_1
|
624
|
+
[1m[36m (0.1ms)[0m [1mSELECT COUNT(*) FROM "users" WHERE "users"."ident" IS NULL[0m
|
625
|
+
[1m[35m (2.4ms)[0m rollback transaction
|
626
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
627
|
+
----------------------------
|
628
|
+
UserTest: test_new_public_id
|
629
|
+
----------------------------
|
630
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
631
|
+
[1m[36m (0.2ms)[0m [1mbegin transaction[0m
|
632
|
+
------------------------------------------
|
633
|
+
UserTest: test_to_param_matches_identifier
|
634
|
+
------------------------------------------
|
635
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
636
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
637
|
+
-------------------------------
|
638
|
+
UserTest: test_use_group-by_sql
|
639
|
+
-------------------------------
|
640
|
+
[1m[35mUser Load (0.2ms)[0m SELECT name, count(name) as count FROM "users" GROUP BY "users"."name"
|
641
|
+
[1m[36mUser Load (0.1ms)[0m [1mSELECT "users".* FROM "users"[0m
|
642
|
+
[1m[35mUser Load (0.1ms)[0m SELECT "users".* FROM "users"
|
643
|
+
[1m[36m (0.0ms)[0m [1mrollback transaction[0m
|
@@ -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
|