phonelib 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +2 -1
- data/lib/phonelib/core.rb +2 -0
- data/lib/phonelib/phone.rb +4 -2
- data/lib/phonelib/version.rb +1 -1
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/test.log +210 -0
- data/test/phonelib_test.rb +168 -98
- data/test/test_helper.rb +1 -0
- metadata +23 -12
data/README.rdoc
CHANGED
@@ -66,8 +66,9 @@ Additional methods:
|
|
66
66
|
|
67
67
|
There is also option to check if provided phone is valid for specified country.
|
68
68
|
Country should be specified as two letters country code (like "US" for United States).
|
69
|
+
Country can be specified as String <tt>'US'</tt> or <tt>'us'</tt> as well as symbol <tt>:us</tt>.
|
69
70
|
|
70
|
-
Phonelib.valid_for_country? '123456789', 'XX' # checks if passed value is valid number for specified country
|
71
|
+
Phonelib.valid_for_country? '123456789', 'XX' # checks if passed value is valid number for specified country
|
71
72
|
Phonelib.invalid_for_country? '123456789', 'XX' # checks if passed value is invalid number for specified country
|
72
73
|
|
73
74
|
Additionally you can run:
|
data/lib/phonelib/core.rb
CHANGED
@@ -123,11 +123,13 @@ module Phonelib
|
|
123
123
|
|
124
124
|
# method checks if passed phone number is valid for provided country
|
125
125
|
def valid_for_country?(phone_number, country)
|
126
|
+
country = country.to_s.upcase
|
126
127
|
parse(phone_number, country).valid_for_country?(country)
|
127
128
|
end
|
128
129
|
|
129
130
|
# method checks if passed phone number is invalid for provided country
|
130
131
|
def invalid_for_country?(phone_number, country)
|
132
|
+
country = country.to_s.upcase
|
131
133
|
parse(phone_number, country).invalid_for_country?(country)
|
132
134
|
end
|
133
135
|
|
data/lib/phonelib/phone.rb
CHANGED
@@ -96,9 +96,10 @@ module Phonelib
|
|
96
96
|
#
|
97
97
|
# ==== Attributes
|
98
98
|
#
|
99
|
-
# * +country+ - ISO code of country (2 letters) like 'US' for United States
|
99
|
+
# * +country+ - ISO code of country (2 letters) like 'US', 'us' or :us for United States
|
100
100
|
#
|
101
101
|
def valid_for_country?(country)
|
102
|
+
country = country.to_s.upcase
|
102
103
|
@analyzed_data.select {|iso2, data| country == iso2 &&
|
103
104
|
data[:valid].any? }.any?
|
104
105
|
end
|
@@ -108,9 +109,10 @@ module Phonelib
|
|
108
109
|
#
|
109
110
|
# ==== Attributes
|
110
111
|
#
|
111
|
-
# * +country+ - ISO code of country (2 letters) like 'US' for United States
|
112
|
+
# * +country+ - ISO code of country (2 letters) like 'US', 'us' or :us for United States
|
112
113
|
#
|
113
114
|
def invalid_for_country?(country)
|
115
|
+
country = country.to_s.upcase
|
114
116
|
@analyzed_data.select {|iso2, data| country == iso2 &&
|
115
117
|
data[:valid].any? }.empty?
|
116
118
|
end
|
data/lib/phonelib/version.rb
CHANGED
data/test/dummy/db/test.sqlite3
CHANGED
Binary file
|
data/test/dummy/log/test.log
CHANGED
@@ -501,3 +501,213 @@ Processing by PhonesController#update as HTML
|
|
501
501
|
Redirected to http://test.host/phones/450723037
|
502
502
|
Completed 302 Found in 3ms (ActiveRecord: 0.1ms)
|
503
503
|
[1m[35m (0.0ms)[0m rollback transaction
|
504
|
+
Connecting to database specified by database.yml
|
505
|
+
[1m[36m (0.3ms)[0m [1mbegin transaction[0m
|
506
|
+
[1m[35mFixture Delete (0.1ms)[0m DELETE FROM "phones"
|
507
|
+
[1m[36mFixture Insert (0.1ms)[0m [1mINSERT INTO "phones" ("number", "possible_number", "created_at", "updated_at", "id") VALUES ('972541234567', '972541234567', '2013-06-04 11:25:00', '2013-06-04 11:25:00', 450723037)[0m
|
508
|
+
[1m[35mFixture Insert (0.0ms)[0m INSERT INTO "phones" ("number", "created_at", "updated_at", "id") VALUES ('wrong', '2013-06-04 11:25:00', '2013-06-04 11:25:00', 667262234)
|
509
|
+
[1m[36mFixture Insert (0.1ms)[0m [1mINSERT INTO "phones" ("number", "created_at", "updated_at", "id") VALUES ('972541234567', '2013-06-04 11:25:00', '2013-06-04 11:25:00', 512636273)[0m
|
510
|
+
[1m[35mFixture Insert (0.1ms)[0m INSERT INTO "phones" ("possible_number", "created_at", "updated_at", "id") VALUES ('972541234567', '2013-06-04 11:25:00', '2013-06-04 11:25:00', 23760034)
|
511
|
+
[1m[36mFixture Insert (0.0ms)[0m [1mINSERT INTO "phones" ("number", "possible_number", "created_at", "updated_at", "id") VALUES ('972541234567', 'wrong', '2013-06-04 11:25:00', '2013-06-04 11:25:00', 703612349)[0m
|
512
|
+
[1m[35m (8.0ms)[0m commit transaction
|
513
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
514
|
+
[1m[35mPhone Load (1.5ms)[0m SELECT "phones".* FROM "phones" WHERE "phones"."id" = ? LIMIT 1 [["id", 512636273]]
|
515
|
+
[1m[36m (0.0ms)[0m [1mSAVEPOINT active_record_1[0m
|
516
|
+
[1m[35m (0.1ms)[0m RELEASE SAVEPOINT active_record_1
|
517
|
+
[1m[36m (0.0ms)[0m [1mrollback transaction[0m
|
518
|
+
[1m[35m (0.0ms)[0m begin transaction
|
519
|
+
[1m[36m (0.0ms)[0m [1mSAVEPOINT active_record_1[0m
|
520
|
+
[1m[35m (0.0ms)[0m ROLLBACK TO SAVEPOINT active_record_1
|
521
|
+
[1m[36m (0.0ms)[0m [1mrollback transaction[0m
|
522
|
+
[1m[35m (0.0ms)[0m begin transaction
|
523
|
+
[1m[36m (0.0ms)[0m [1mSAVEPOINT active_record_1[0m
|
524
|
+
[1m[35mSQL (1.3ms)[0m INSERT INTO "phones" ("created_at", "number", "possible_number", "updated_at") VALUES (?, ?, ?, ?) [["created_at", Tue, 04 Jun 2013 11:25:00 UTC +00:00], ["number", "972541234567"], ["possible_number", nil], ["updated_at", Tue, 04 Jun 2013 11:25:00 UTC +00:00]]
|
525
|
+
[1m[36m (0.1ms)[0m [1mRELEASE SAVEPOINT active_record_1[0m
|
526
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
527
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
528
|
+
[1m[35mPhone Load (0.1ms)[0m SELECT "phones".* FROM "phones" WHERE "phones"."id" = ? LIMIT 1 [["id", 450723037]]
|
529
|
+
[1m[36m (0.0ms)[0m [1mSAVEPOINT active_record_1[0m
|
530
|
+
[1m[35m (0.1ms)[0m RELEASE SAVEPOINT active_record_1
|
531
|
+
[1m[36m (0.0ms)[0m [1mrollback transaction[0m
|
532
|
+
[1m[35m (0.0ms)[0m begin transaction
|
533
|
+
[1m[36mPhone Load (0.0ms)[0m [1mSELECT "phones".* FROM "phones" WHERE "phones"."id" = ? LIMIT 1[0m [["id", 23760034]]
|
534
|
+
[1m[35m (0.0ms)[0m SAVEPOINT active_record_1
|
535
|
+
[1m[36m (0.0ms)[0m [1mROLLBACK TO SAVEPOINT active_record_1[0m
|
536
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
537
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
538
|
+
[1m[35mPhone Load (0.0ms)[0m SELECT "phones".* FROM "phones" WHERE "phones"."id" = ? LIMIT 1 [["id", 667262234]]
|
539
|
+
[1m[36m (0.0ms)[0m [1mSAVEPOINT active_record_1[0m
|
540
|
+
[1m[35m (0.0ms)[0m ROLLBACK TO SAVEPOINT active_record_1
|
541
|
+
[1m[36m (0.0ms)[0m [1mrollback transaction[0m
|
542
|
+
[1m[35m (0.0ms)[0m begin transaction
|
543
|
+
[1m[36mPhone Load (0.0ms)[0m [1mSELECT "phones".* FROM "phones" WHERE "phones"."id" = ? LIMIT 1[0m [["id", 703612349]]
|
544
|
+
[1m[35m (0.0ms)[0m SAVEPOINT active_record_1
|
545
|
+
[1m[36m (0.0ms)[0m [1mROLLBACK TO SAVEPOINT active_record_1[0m
|
546
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
547
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
548
|
+
[1m[35mPhone Load (0.1ms)[0m SELECT "phones".* FROM "phones" WHERE "phones"."id" = ? LIMIT 1 [["id", 450723037]]
|
549
|
+
[1m[36m (0.1ms)[0m [1mSELECT COUNT(*) FROM "phones" [0m
|
550
|
+
Processing by PhonesController#create as HTML
|
551
|
+
Parameters: {"phone"=>{"number"=>"972541234567"}}
|
552
|
+
[1m[35m (0.0ms)[0m SAVEPOINT active_record_1
|
553
|
+
[1m[36mSQL (0.2ms)[0m [1mINSERT INTO "phones" ("created_at", "number", "possible_number", "updated_at") VALUES (?, ?, ?, ?)[0m [["created_at", Tue, 04 Jun 2013 11:25:00 UTC +00:00], ["number", "972541234567"], ["possible_number", nil], ["updated_at", Tue, 04 Jun 2013 11:25:00 UTC +00:00]]
|
554
|
+
[1m[35m (0.0ms)[0m RELEASE SAVEPOINT active_record_1
|
555
|
+
Redirected to http://test.host/phones/703612350
|
556
|
+
Completed 302 Found in 3ms (ActiveRecord: 0.2ms)
|
557
|
+
[1m[36m (0.0ms)[0m [1mSELECT COUNT(*) FROM "phones" [0m
|
558
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
559
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
560
|
+
[1m[35mPhone Load (0.0ms)[0m SELECT "phones".* FROM "phones" WHERE "phones"."id" = ? LIMIT 1 [["id", 450723037]]
|
561
|
+
[1m[36m (0.0ms)[0m [1mSELECT COUNT(*) FROM "phones" [0m
|
562
|
+
Processing by PhonesController#destroy as HTML
|
563
|
+
Parameters: {"id"=>"450723037"}
|
564
|
+
[1m[35mPhone Load (0.0ms)[0m SELECT "phones".* FROM "phones" WHERE "phones"."id" = ? LIMIT 1 [["id", "450723037"]]
|
565
|
+
[1m[36m (0.0ms)[0m [1mSAVEPOINT active_record_1[0m
|
566
|
+
[1m[35mSQL (0.1ms)[0m DELETE FROM "phones" WHERE "phones"."id" = ? [["id", 450723037]]
|
567
|
+
[1m[36m (0.0ms)[0m [1mRELEASE SAVEPOINT active_record_1[0m
|
568
|
+
Redirected to http://test.host/phones
|
569
|
+
Completed 302 Found in 1ms (ActiveRecord: 0.2ms)
|
570
|
+
[1m[35m (0.0ms)[0m SELECT COUNT(*) FROM "phones"
|
571
|
+
[1m[36m (0.1ms)[0m [1mrollback transaction[0m
|
572
|
+
[1m[35m (0.0ms)[0m begin transaction
|
573
|
+
[1m[36mPhone Load (0.0ms)[0m [1mSELECT "phones".* FROM "phones" WHERE "phones"."id" = ? LIMIT 1[0m [["id", 450723037]]
|
574
|
+
Processing by PhonesController#edit as HTML
|
575
|
+
Parameters: {"id"=>"450723037"}
|
576
|
+
[1m[35mPhone Load (0.0ms)[0m SELECT "phones".* FROM "phones" WHERE "phones"."id" = ? LIMIT 1 [["id", "450723037"]]
|
577
|
+
Rendered phones/_form.html.erb (5.4ms)
|
578
|
+
Completed 200 OK in 50ms (Views: 49.2ms | ActiveRecord: 0.0ms)
|
579
|
+
[1m[36m (0.1ms)[0m [1mrollback transaction[0m
|
580
|
+
[1m[35m (0.0ms)[0m begin transaction
|
581
|
+
[1m[36mPhone Load (0.1ms)[0m [1mSELECT "phones".* FROM "phones" WHERE "phones"."id" = ? LIMIT 1[0m [["id", 450723037]]
|
582
|
+
Processing by PhonesController#index as HTML
|
583
|
+
[1m[35mPhone Load (0.1ms)[0m SELECT "phones".* FROM "phones"
|
584
|
+
Completed 200 OK in 4ms (Views: 3.5ms | ActiveRecord: 0.1ms)
|
585
|
+
[1m[36m (0.0ms)[0m [1mrollback transaction[0m
|
586
|
+
[1m[35m (0.0ms)[0m begin transaction
|
587
|
+
[1m[36mPhone Load (0.0ms)[0m [1mSELECT "phones".* FROM "phones" WHERE "phones"."id" = ? LIMIT 1[0m [["id", 450723037]]
|
588
|
+
Processing by PhonesController#new as HTML
|
589
|
+
Rendered phones/_form.html.erb (1.2ms)
|
590
|
+
Completed 200 OK in 3ms (Views: 2.5ms | ActiveRecord: 0.0ms)
|
591
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
592
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
593
|
+
[1m[35mPhone Load (0.0ms)[0m SELECT "phones".* FROM "phones" WHERE "phones"."id" = ? LIMIT 1 [["id", 450723037]]
|
594
|
+
Processing by PhonesController#show as HTML
|
595
|
+
Parameters: {"id"=>"450723037"}
|
596
|
+
[1m[36mPhone Load (0.0ms)[0m [1mSELECT "phones".* FROM "phones" WHERE "phones"."id" = ? LIMIT 1[0m [["id", "450723037"]]
|
597
|
+
Completed 200 OK in 2ms (Views: 1.4ms | ActiveRecord: 0.0ms)
|
598
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
599
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
600
|
+
[1m[35mPhone Load (0.0ms)[0m SELECT "phones".* FROM "phones" WHERE "phones"."id" = ? LIMIT 1 [["id", 450723037]]
|
601
|
+
Processing by PhonesController#update as HTML
|
602
|
+
Parameters: {"phone"=>{"number"=>"972541234567"}, "id"=>"450723037"}
|
603
|
+
[1m[36mPhone Load (0.0ms)[0m [1mSELECT "phones".* FROM "phones" WHERE "phones"."id" = ? LIMIT 1[0m [["id", "450723037"]]
|
604
|
+
[1m[35m (0.0ms)[0m SAVEPOINT active_record_1
|
605
|
+
[1m[36m (0.0ms)[0m [1mRELEASE SAVEPOINT active_record_1[0m
|
606
|
+
Redirected to http://test.host/phones/450723037
|
607
|
+
Completed 302 Found in 3ms (ActiveRecord: 0.1ms)
|
608
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
609
|
+
Connecting to database specified by database.yml
|
610
|
+
[1m[36m (0.2ms)[0m [1mbegin transaction[0m
|
611
|
+
[1m[35mFixture Delete (0.1ms)[0m DELETE FROM "phones"
|
612
|
+
[1m[36mFixture Insert (0.1ms)[0m [1mINSERT INTO "phones" ("number", "possible_number", "created_at", "updated_at", "id") VALUES ('972541234567', '972541234567', '2013-06-04 11:25:09', '2013-06-04 11:25:09', 450723037)[0m
|
613
|
+
[1m[35mFixture Insert (0.0ms)[0m INSERT INTO "phones" ("number", "created_at", "updated_at", "id") VALUES ('wrong', '2013-06-04 11:25:09', '2013-06-04 11:25:09', 667262234)
|
614
|
+
[1m[36mFixture Insert (0.0ms)[0m [1mINSERT INTO "phones" ("number", "created_at", "updated_at", "id") VALUES ('972541234567', '2013-06-04 11:25:09', '2013-06-04 11:25:09', 512636273)[0m
|
615
|
+
[1m[35mFixture Insert (0.0ms)[0m INSERT INTO "phones" ("possible_number", "created_at", "updated_at", "id") VALUES ('972541234567', '2013-06-04 11:25:09', '2013-06-04 11:25:09', 23760034)
|
616
|
+
[1m[36mFixture Insert (0.0ms)[0m [1mINSERT INTO "phones" ("number", "possible_number", "created_at", "updated_at", "id") VALUES ('972541234567', 'wrong', '2013-06-04 11:25:09', '2013-06-04 11:25:09', 703612349)[0m
|
617
|
+
[1m[35m (3.2ms)[0m commit transaction
|
618
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
619
|
+
[1m[35mPhone Load (1.4ms)[0m SELECT "phones".* FROM "phones" WHERE "phones"."id" = ? LIMIT 1 [["id", 512636273]]
|
620
|
+
[1m[36m (0.1ms)[0m [1mSAVEPOINT active_record_1[0m
|
621
|
+
[1m[35m (0.1ms)[0m RELEASE SAVEPOINT active_record_1
|
622
|
+
[1m[36m (0.0ms)[0m [1mrollback transaction[0m
|
623
|
+
[1m[35m (0.0ms)[0m begin transaction
|
624
|
+
[1m[36m (0.0ms)[0m [1mSAVEPOINT active_record_1[0m
|
625
|
+
[1m[35m (0.0ms)[0m ROLLBACK TO SAVEPOINT active_record_1
|
626
|
+
[1m[36m (0.0ms)[0m [1mrollback transaction[0m
|
627
|
+
[1m[35m (0.0ms)[0m begin transaction
|
628
|
+
[1m[36m (0.0ms)[0m [1mSAVEPOINT active_record_1[0m
|
629
|
+
[1m[35mSQL (0.7ms)[0m INSERT INTO "phones" ("created_at", "number", "possible_number", "updated_at") VALUES (?, ?, ?, ?) [["created_at", Tue, 04 Jun 2013 11:25:09 UTC +00:00], ["number", "972541234567"], ["possible_number", nil], ["updated_at", Tue, 04 Jun 2013 11:25:09 UTC +00:00]]
|
630
|
+
[1m[36m (0.0ms)[0m [1mRELEASE SAVEPOINT active_record_1[0m
|
631
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
632
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
633
|
+
[1m[35mPhone Load (0.0ms)[0m SELECT "phones".* FROM "phones" WHERE "phones"."id" = ? LIMIT 1 [["id", 450723037]]
|
634
|
+
[1m[36m (0.0ms)[0m [1mSAVEPOINT active_record_1[0m
|
635
|
+
[1m[35m (0.0ms)[0m RELEASE SAVEPOINT active_record_1
|
636
|
+
[1m[36m (0.0ms)[0m [1mrollback transaction[0m
|
637
|
+
[1m[35m (0.0ms)[0m begin transaction
|
638
|
+
[1m[36mPhone Load (0.0ms)[0m [1mSELECT "phones".* FROM "phones" WHERE "phones"."id" = ? LIMIT 1[0m [["id", 23760034]]
|
639
|
+
[1m[35m (0.0ms)[0m SAVEPOINT active_record_1
|
640
|
+
[1m[36m (0.0ms)[0m [1mROLLBACK TO SAVEPOINT active_record_1[0m
|
641
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
642
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
643
|
+
[1m[35mPhone Load (0.0ms)[0m SELECT "phones".* FROM "phones" WHERE "phones"."id" = ? LIMIT 1 [["id", 667262234]]
|
644
|
+
[1m[36m (0.0ms)[0m [1mSAVEPOINT active_record_1[0m
|
645
|
+
[1m[35m (0.0ms)[0m ROLLBACK TO SAVEPOINT active_record_1
|
646
|
+
[1m[36m (0.0ms)[0m [1mrollback transaction[0m
|
647
|
+
[1m[35m (0.0ms)[0m begin transaction
|
648
|
+
[1m[36mPhone Load (0.0ms)[0m [1mSELECT "phones".* FROM "phones" WHERE "phones"."id" = ? LIMIT 1[0m [["id", 703612349]]
|
649
|
+
[1m[35m (0.0ms)[0m SAVEPOINT active_record_1
|
650
|
+
[1m[36m (0.0ms)[0m [1mROLLBACK TO SAVEPOINT active_record_1[0m
|
651
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
652
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
653
|
+
[1m[35mPhone Load (0.1ms)[0m SELECT "phones".* FROM "phones" WHERE "phones"."id" = ? LIMIT 1 [["id", 450723037]]
|
654
|
+
[1m[36m (0.1ms)[0m [1mSELECT COUNT(*) FROM "phones" [0m
|
655
|
+
Processing by PhonesController#create as HTML
|
656
|
+
Parameters: {"phone"=>{"number"=>"972541234567"}}
|
657
|
+
[1m[35m (0.0ms)[0m SAVEPOINT active_record_1
|
658
|
+
[1m[36mSQL (0.2ms)[0m [1mINSERT INTO "phones" ("created_at", "number", "possible_number", "updated_at") VALUES (?, ?, ?, ?)[0m [["created_at", Tue, 04 Jun 2013 11:25:09 UTC +00:00], ["number", "972541234567"], ["possible_number", nil], ["updated_at", Tue, 04 Jun 2013 11:25:09 UTC +00:00]]
|
659
|
+
[1m[35m (0.0ms)[0m RELEASE SAVEPOINT active_record_1
|
660
|
+
Redirected to http://test.host/phones/703612350
|
661
|
+
Completed 302 Found in 3ms (ActiveRecord: 0.3ms)
|
662
|
+
[1m[36m (0.0ms)[0m [1mSELECT COUNT(*) FROM "phones" [0m
|
663
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
664
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
665
|
+
[1m[35mPhone Load (0.0ms)[0m SELECT "phones".* FROM "phones" WHERE "phones"."id" = ? LIMIT 1 [["id", 450723037]]
|
666
|
+
[1m[36m (0.0ms)[0m [1mSELECT COUNT(*) FROM "phones" [0m
|
667
|
+
Processing by PhonesController#destroy as HTML
|
668
|
+
Parameters: {"id"=>"450723037"}
|
669
|
+
[1m[35mPhone Load (0.0ms)[0m SELECT "phones".* FROM "phones" WHERE "phones"."id" = ? LIMIT 1 [["id", "450723037"]]
|
670
|
+
[1m[36m (0.0ms)[0m [1mSAVEPOINT active_record_1[0m
|
671
|
+
[1m[35mSQL (0.1ms)[0m DELETE FROM "phones" WHERE "phones"."id" = ? [["id", 450723037]]
|
672
|
+
[1m[36m (0.0ms)[0m [1mRELEASE SAVEPOINT active_record_1[0m
|
673
|
+
Redirected to http://test.host/phones
|
674
|
+
Completed 302 Found in 1ms (ActiveRecord: 0.2ms)
|
675
|
+
[1m[35m (0.0ms)[0m SELECT COUNT(*) FROM "phones"
|
676
|
+
[1m[36m (0.0ms)[0m [1mrollback transaction[0m
|
677
|
+
[1m[35m (0.0ms)[0m begin transaction
|
678
|
+
[1m[36mPhone Load (0.0ms)[0m [1mSELECT "phones".* FROM "phones" WHERE "phones"."id" = ? LIMIT 1[0m [["id", 450723037]]
|
679
|
+
Processing by PhonesController#edit as HTML
|
680
|
+
Parameters: {"id"=>"450723037"}
|
681
|
+
[1m[35mPhone Load (0.0ms)[0m SELECT "phones".* FROM "phones" WHERE "phones"."id" = ? LIMIT 1 [["id", "450723037"]]
|
682
|
+
Rendered phones/_form.html.erb (20.1ms)
|
683
|
+
Completed 200 OK in 47ms (Views: 46.1ms | ActiveRecord: 0.0ms)
|
684
|
+
[1m[36m (0.1ms)[0m [1mrollback transaction[0m
|
685
|
+
[1m[35m (0.0ms)[0m begin transaction
|
686
|
+
[1m[36mPhone Load (0.1ms)[0m [1mSELECT "phones".* FROM "phones" WHERE "phones"."id" = ? LIMIT 1[0m [["id", 450723037]]
|
687
|
+
Processing by PhonesController#index as HTML
|
688
|
+
[1m[35mPhone Load (0.1ms)[0m SELECT "phones".* FROM "phones"
|
689
|
+
Completed 200 OK in 4ms (Views: 3.4ms | ActiveRecord: 0.1ms)
|
690
|
+
[1m[36m (0.0ms)[0m [1mrollback transaction[0m
|
691
|
+
[1m[35m (0.0ms)[0m begin transaction
|
692
|
+
[1m[36mPhone Load (0.0ms)[0m [1mSELECT "phones".* FROM "phones" WHERE "phones"."id" = ? LIMIT 1[0m [["id", 450723037]]
|
693
|
+
Processing by PhonesController#new as HTML
|
694
|
+
Rendered phones/_form.html.erb (1.2ms)
|
695
|
+
Completed 200 OK in 3ms (Views: 2.4ms | ActiveRecord: 0.0ms)
|
696
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
697
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
698
|
+
[1m[35mPhone Load (0.0ms)[0m SELECT "phones".* FROM "phones" WHERE "phones"."id" = ? LIMIT 1 [["id", 450723037]]
|
699
|
+
Processing by PhonesController#show as HTML
|
700
|
+
Parameters: {"id"=>"450723037"}
|
701
|
+
[1m[36mPhone Load (0.0ms)[0m [1mSELECT "phones".* FROM "phones" WHERE "phones"."id" = ? LIMIT 1[0m [["id", "450723037"]]
|
702
|
+
Completed 200 OK in 2ms (Views: 1.3ms | ActiveRecord: 0.0ms)
|
703
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
704
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
705
|
+
[1m[35mPhone Load (0.0ms)[0m SELECT "phones".* FROM "phones" WHERE "phones"."id" = ? LIMIT 1 [["id", 450723037]]
|
706
|
+
Processing by PhonesController#update as HTML
|
707
|
+
Parameters: {"phone"=>{"number"=>"972541234567"}, "id"=>"450723037"}
|
708
|
+
[1m[36mPhone Load (0.0ms)[0m [1mSELECT "phones".* FROM "phones" WHERE "phones"."id" = ? LIMIT 1[0m [["id", "450723037"]]
|
709
|
+
[1m[35m (0.0ms)[0m SAVEPOINT active_record_1
|
710
|
+
[1m[36m (0.0ms)[0m [1mRELEASE SAVEPOINT active_record_1[0m
|
711
|
+
Redirected to http://test.host/phones/450723037
|
712
|
+
Completed 302 Found in 3ms (ActiveRecord: 0.1ms)
|
713
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
data/test/phonelib_test.rb
CHANGED
@@ -1,105 +1,175 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
class PhonelibTest <
|
4
|
-
test "truth" do
|
5
|
-
assert_kind_of Module, Phonelib
|
6
|
-
end
|
7
|
-
|
8
|
-
test "returns phone object" do
|
9
|
-
assert Phonelib.parse('972541234567').is_a? Phonelib::Phone
|
10
|
-
end
|
11
|
-
|
12
|
-
test "valid? with malformed phone number" do
|
13
|
-
assert !Phonelib.valid?('sdffsd')
|
14
|
-
end
|
15
|
-
|
16
|
-
test "invalid? with malformed phone number" do
|
17
|
-
assert Phonelib.invalid?('sdffsd')
|
18
|
-
end
|
19
|
-
|
20
|
-
test "valid? with valid phone number" do
|
21
|
-
assert Phonelib.valid? '972541234567'
|
22
|
-
end
|
23
|
-
|
24
|
-
test "invalid? with valid phone number" do
|
25
|
-
assert !Phonelib.invalid?('972541234567')
|
26
|
-
end
|
27
|
-
|
28
|
-
test "possible? with valid phone number" do
|
29
|
-
assert Phonelib.possible? '972541234567'
|
30
|
-
end
|
31
|
-
|
32
|
-
test "impossible? with valid phone number" do
|
33
|
-
assert !Phonelib.impossible?('972541234567')
|
34
|
-
end
|
35
|
-
|
36
|
-
test "valid? with invalid phone number" do
|
37
|
-
assert !Phonelib.valid?('97254123')
|
38
|
-
end
|
39
|
-
|
40
|
-
test "invalid? with invalid phone number" do
|
41
|
-
assert Phonelib.invalid?('97254123')
|
42
|
-
end
|
43
|
-
|
44
|
-
test "possible? with invalid phone number" do
|
45
|
-
assert !Phonelib.possible?('97254123')
|
46
|
-
end
|
47
|
-
|
48
|
-
test "impossible? with invalid phone number" do
|
49
|
-
assert Phonelib.impossible?('97254123')
|
50
|
-
end
|
3
|
+
class PhonelibTest < Test::Unit::TestCase
|
51
4
|
|
52
|
-
|
53
|
-
|
54
|
-
assert !phone.valid?
|
55
|
-
assert phone.possible?
|
56
|
-
end
|
57
|
-
|
58
|
-
test "valid_for_country? with correct data" do
|
59
|
-
assert Phonelib.valid_for_country?('972541234567', 'IL')
|
60
|
-
end
|
61
|
-
|
62
|
-
test "valid_for_country? with correct data and national number" do
|
63
|
-
assert Phonelib.valid_for_country?('0541234567', 'IL')
|
64
|
-
end
|
65
|
-
|
66
|
-
test "valid_for_country? with correct data and without prefix" do
|
67
|
-
assert Phonelib.valid_for_country?('541234567', 'IL')
|
68
|
-
end
|
69
|
-
|
70
|
-
test "valid_for_country? with fake data and without prefix" do
|
71
|
-
assert !Phonelib.valid_for_country?('541234567', 'US')
|
72
|
-
end
|
73
|
-
|
74
|
-
test "invalid_for_country? with correct data" do
|
75
|
-
assert !Phonelib.invalid_for_country?('972541234567', 'IL')
|
76
|
-
end
|
77
|
-
|
78
|
-
test "invalid_for_country? with incorrect data" do
|
79
|
-
assert Phonelib.invalid_for_country?('972541234567', 'US')
|
80
|
-
end
|
81
|
-
|
82
|
-
test "valid_for_country? with incorrect data" do
|
83
|
-
assert !Phonelib.valid_for_country?('972541234567', 'US')
|
84
|
-
end
|
85
|
-
|
86
|
-
test "international method returns with right formatting" do
|
87
|
-
phone = Phonelib.parse('972541234567')
|
88
|
-
assert phone.international == '+972 54-123-4567'
|
89
|
-
end
|
90
|
-
|
91
|
-
test "national method returns right formatting" do
|
92
|
-
phone = Phonelib.parse('972541234567')
|
93
|
-
assert phone.national == '054-123-4567'
|
94
|
-
end
|
95
|
-
|
96
|
-
test "international method returns sanitized when number invalid but possible" do
|
97
|
-
phone = Phonelib.parse('9721234567')
|
98
|
-
assert phone.international == '+9721234567'
|
5
|
+
should 'be a Module' do
|
6
|
+
assert_kind_of Module, Phonelib
|
99
7
|
end
|
100
8
|
|
101
|
-
|
102
|
-
phone = Phonelib.parse
|
103
|
-
|
9
|
+
context '.parse' do
|
10
|
+
setup { @phone = Phonelib.parse '9721234567' }
|
11
|
+
|
12
|
+
should 'return a Phone object' do
|
13
|
+
assert @phone.is_a? Phonelib::Phone #instance_of?
|
14
|
+
end
|
15
|
+
|
16
|
+
should 'be possible but not valid phone number' do
|
17
|
+
assert !@phone.valid?
|
18
|
+
assert @phone.possible?
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context '.valid?' do
|
23
|
+
context 'with malformed phone number' do
|
24
|
+
should 'not be valid' do
|
25
|
+
assert !Phonelib.valid?('sdffsd')
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'with valid phone number' do
|
30
|
+
should 'be valid' do
|
31
|
+
assert Phonelib.valid?('972541234567')
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'with invalid phone number' do
|
36
|
+
should 'not be valid' do
|
37
|
+
assert !Phonelib.valid?('97254123')
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context '.invalid?' do
|
43
|
+
context 'with malformed phone number' do
|
44
|
+
should 'be valid' do
|
45
|
+
assert Phonelib.invalid?('sdffsd')
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context 'with valid phone number' do
|
50
|
+
should 'not be valid' do
|
51
|
+
assert !Phonelib.invalid?('972541234567')
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context 'with invalid phone number' do
|
56
|
+
should 'be valid' do
|
57
|
+
assert Phonelib.invalid?('97254123')
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
context '.possible?' do
|
63
|
+
context 'with valid phone number' do
|
64
|
+
should 'be valid' do
|
65
|
+
assert Phonelib.possible? '972541234567'
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context 'with invalid phone number' do
|
70
|
+
should 'not be valid' do
|
71
|
+
assert !Phonelib.possible?('97254123')
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
context '.impossible?' do
|
77
|
+
context 'with valid phone number' do
|
78
|
+
should 'not be valid' do
|
79
|
+
assert !Phonelib.impossible?('972541234567')
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
context 'with invalid phone number' do
|
84
|
+
should 'be valid' do
|
85
|
+
assert Phonelib.impossible?('97254123')
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
context 'valid_for_country?' do
|
91
|
+
context 'with correct data' do
|
92
|
+
['IL', :il].each do |country|
|
93
|
+
context "with #{country} as country" do
|
94
|
+
should 'be valid' do
|
95
|
+
assert Phonelib.valid_for_country?('972541234567', country)
|
96
|
+
end
|
97
|
+
|
98
|
+
context 'and national number' do
|
99
|
+
should 'be valid' do
|
100
|
+
assert Phonelib.valid_for_country?('0541234567', country)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
context 'and without prefix' do
|
105
|
+
should 'be valid' do
|
106
|
+
assert Phonelib.valid_for_country?('541234567', country)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
['US', :us].each do |country|
|
114
|
+
context "with #{country} as country" do
|
115
|
+
context 'with incorrect data' do
|
116
|
+
should 'not be valid' do
|
117
|
+
assert !Phonelib.valid_for_country?('972541234567', country)
|
118
|
+
end
|
119
|
+
|
120
|
+
context 'and without prefix' do
|
121
|
+
should 'not be valid' do
|
122
|
+
assert !Phonelib.valid_for_country?('541234567', country)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
context '.invalid_for_country?' do
|
131
|
+
context 'with correct data' do
|
132
|
+
['IL', :il].each do |country|
|
133
|
+
context "with #{country} as country" do
|
134
|
+
should 'not be invalid' do
|
135
|
+
assert !Phonelib.invalid_for_country?('972541234567', country)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
context 'with incorrect data' do
|
142
|
+
['US', :us].each do |country|
|
143
|
+
context "with #{country} as country" do
|
144
|
+
should 'be invalid' do
|
145
|
+
assert Phonelib.invalid_for_country?('972541234567', country)
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
context '#international' do
|
153
|
+
should 'return right formatting' do
|
154
|
+
phone = Phonelib.parse('972541234567')
|
155
|
+
assert_equal '+972 54-123-4567', phone.international
|
156
|
+
end
|
157
|
+
|
158
|
+
should 'return sanitized when number invalid but possible' do
|
159
|
+
phone = Phonelib.parse('9721234567')
|
160
|
+
assert_equal '+9721234567', phone.international
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
context '#national' do
|
165
|
+
should 'return right formatting' do
|
166
|
+
phone = Phonelib.parse('972541234567')
|
167
|
+
assert_equal '054-123-4567', phone.national
|
168
|
+
end
|
169
|
+
|
170
|
+
should 'return sanitized national when number invalid but possible' do
|
171
|
+
phone = Phonelib.parse('9721234567')
|
172
|
+
assert_equal '1234567', phone.national
|
173
|
+
end
|
104
174
|
end
|
105
175
|
end
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: phonelib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-06-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
16
|
-
requirement: &
|
16
|
+
requirement: &16799660 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 3.1.0
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *16799660
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: sqlite3
|
27
|
-
requirement: &
|
27
|
+
requirement: &16798880 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *16798880
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: nokogiri
|
38
|
-
requirement: &
|
38
|
+
requirement: &16798100 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *16798100
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: pry
|
49
|
-
requirement: &
|
49
|
+
requirement: &16797520 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,7 +54,18 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *16797520
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: shoulda-context
|
60
|
+
requirement: &16812780 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *16812780
|
58
69
|
description: Google libphonenumber library was taken as a basis for this gem. Gem
|
59
70
|
uses its data file for validations and number formatting.
|
60
71
|
email:
|
@@ -140,7 +151,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
140
151
|
version: '0'
|
141
152
|
segments:
|
142
153
|
- 0
|
143
|
-
hash: -
|
154
|
+
hash: -3279311756524952589
|
144
155
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
145
156
|
none: false
|
146
157
|
requirements:
|
@@ -149,7 +160,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
149
160
|
version: '0'
|
150
161
|
segments:
|
151
162
|
- 0
|
152
|
-
hash: -
|
163
|
+
hash: -3279311756524952589
|
153
164
|
requirements: []
|
154
165
|
rubyforge_project:
|
155
166
|
rubygems_version: 1.8.17
|