phonelib 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
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
 
@@ -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
@@ -1,4 +1,4 @@
1
1
  module Phonelib
2
2
  # :nodoc:
3
- VERSION = "0.1.1"
3
+ VERSION = "0.1.2"
4
4
  end
Binary file
@@ -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
   (0.0ms) rollback transaction
504
+ Connecting to database specified by database.yml
505
+  (0.3ms) begin transaction
506
+ Fixture Delete (0.1ms) DELETE FROM "phones"
507
+ Fixture Insert (0.1ms) INSERT 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)
508
+ Fixture Insert (0.0ms) 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
+ Fixture Insert (0.1ms) INSERT INTO "phones" ("number", "created_at", "updated_at", "id") VALUES ('972541234567', '2013-06-04 11:25:00', '2013-06-04 11:25:00', 512636273)
510
+ Fixture Insert (0.1ms) 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
+ Fixture Insert (0.0ms) INSERT 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)
512
+  (8.0ms) commit transaction
513
+  (0.1ms) begin transaction
514
+ Phone Load (1.5ms) SELECT "phones".* FROM "phones" WHERE "phones"."id" = ? LIMIT 1 [["id", 512636273]]
515
+  (0.0ms) SAVEPOINT active_record_1
516
+  (0.1ms) RELEASE SAVEPOINT active_record_1
517
+  (0.0ms) rollback transaction
518
+  (0.0ms) begin transaction
519
+  (0.0ms) SAVEPOINT active_record_1
520
+  (0.0ms) ROLLBACK TO SAVEPOINT active_record_1
521
+  (0.0ms) rollback transaction
522
+  (0.0ms) begin transaction
523
+  (0.0ms) SAVEPOINT active_record_1
524
+ SQL (1.3ms) 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
+  (0.1ms) RELEASE SAVEPOINT active_record_1
526
+  (0.1ms) rollback transaction
527
+  (0.0ms) begin transaction
528
+ Phone Load (0.1ms) SELECT "phones".* FROM "phones" WHERE "phones"."id" = ? LIMIT 1 [["id", 450723037]]
529
+  (0.0ms) SAVEPOINT active_record_1
530
+  (0.1ms) RELEASE SAVEPOINT active_record_1
531
+  (0.0ms) rollback transaction
532
+  (0.0ms) begin transaction
533
+ Phone Load (0.0ms) SELECT "phones".* FROM "phones" WHERE "phones"."id" = ? LIMIT 1 [["id", 23760034]]
534
+  (0.0ms) SAVEPOINT active_record_1
535
+  (0.0ms) ROLLBACK TO SAVEPOINT active_record_1
536
+  (0.0ms) rollback transaction
537
+  (0.0ms) begin transaction
538
+ Phone Load (0.0ms) SELECT "phones".* FROM "phones" WHERE "phones"."id" = ? LIMIT 1 [["id", 667262234]]
539
+  (0.0ms) SAVEPOINT active_record_1
540
+  (0.0ms) ROLLBACK TO SAVEPOINT active_record_1
541
+  (0.0ms) rollback transaction
542
+  (0.0ms) begin transaction
543
+ Phone Load (0.0ms) SELECT "phones".* FROM "phones" WHERE "phones"."id" = ? LIMIT 1 [["id", 703612349]]
544
+  (0.0ms) SAVEPOINT active_record_1
545
+  (0.0ms) ROLLBACK TO SAVEPOINT active_record_1
546
+  (0.0ms) rollback transaction
547
+  (0.1ms) begin transaction
548
+ Phone Load (0.1ms) SELECT "phones".* FROM "phones" WHERE "phones"."id" = ? LIMIT 1 [["id", 450723037]]
549
+  (0.1ms) SELECT COUNT(*) FROM "phones" 
550
+ Processing by PhonesController#create as HTML
551
+ Parameters: {"phone"=>{"number"=>"972541234567"}}
552
+  (0.0ms) SAVEPOINT active_record_1
553
+ SQL (0.2ms) 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]]
554
+  (0.0ms) RELEASE SAVEPOINT active_record_1
555
+ Redirected to http://test.host/phones/703612350
556
+ Completed 302 Found in 3ms (ActiveRecord: 0.2ms)
557
+  (0.0ms) SELECT COUNT(*) FROM "phones" 
558
+  (0.1ms) rollback transaction
559
+  (0.0ms) begin transaction
560
+ Phone Load (0.0ms) SELECT "phones".* FROM "phones" WHERE "phones"."id" = ? LIMIT 1 [["id", 450723037]]
561
+  (0.0ms) SELECT COUNT(*) FROM "phones" 
562
+ Processing by PhonesController#destroy as HTML
563
+ Parameters: {"id"=>"450723037"}
564
+ Phone Load (0.0ms) SELECT "phones".* FROM "phones" WHERE "phones"."id" = ? LIMIT 1 [["id", "450723037"]]
565
+  (0.0ms) SAVEPOINT active_record_1
566
+ SQL (0.1ms) DELETE FROM "phones" WHERE "phones"."id" = ? [["id", 450723037]]
567
+  (0.0ms) RELEASE SAVEPOINT active_record_1
568
+ Redirected to http://test.host/phones
569
+ Completed 302 Found in 1ms (ActiveRecord: 0.2ms)
570
+  (0.0ms) SELECT COUNT(*) FROM "phones"
571
+  (0.1ms) rollback transaction
572
+  (0.0ms) begin transaction
573
+ Phone Load (0.0ms) SELECT "phones".* FROM "phones" WHERE "phones"."id" = ? LIMIT 1 [["id", 450723037]]
574
+ Processing by PhonesController#edit as HTML
575
+ Parameters: {"id"=>"450723037"}
576
+ Phone Load (0.0ms) 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
+  (0.1ms) rollback transaction
580
+  (0.0ms) begin transaction
581
+ Phone Load (0.1ms) SELECT "phones".* FROM "phones" WHERE "phones"."id" = ? LIMIT 1 [["id", 450723037]]
582
+ Processing by PhonesController#index as HTML
583
+ Phone Load (0.1ms) SELECT "phones".* FROM "phones"
584
+ Completed 200 OK in 4ms (Views: 3.5ms | ActiveRecord: 0.1ms)
585
+  (0.0ms) rollback transaction
586
+  (0.0ms) begin transaction
587
+ Phone Load (0.0ms) SELECT "phones".* FROM "phones" WHERE "phones"."id" = ? LIMIT 1 [["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
+  (0.0ms) rollback transaction
592
+  (0.0ms) begin transaction
593
+ Phone Load (0.0ms) SELECT "phones".* FROM "phones" WHERE "phones"."id" = ? LIMIT 1 [["id", 450723037]]
594
+ Processing by PhonesController#show as HTML
595
+ Parameters: {"id"=>"450723037"}
596
+ Phone Load (0.0ms) SELECT "phones".* FROM "phones" WHERE "phones"."id" = ? LIMIT 1 [["id", "450723037"]]
597
+ Completed 200 OK in 2ms (Views: 1.4ms | ActiveRecord: 0.0ms)
598
+  (0.0ms) rollback transaction
599
+  (0.0ms) begin transaction
600
+ Phone Load (0.0ms) 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
+ Phone Load (0.0ms) SELECT "phones".* FROM "phones" WHERE "phones"."id" = ? LIMIT 1 [["id", "450723037"]]
604
+  (0.0ms) SAVEPOINT active_record_1
605
+  (0.0ms) RELEASE SAVEPOINT active_record_1
606
+ Redirected to http://test.host/phones/450723037
607
+ Completed 302 Found in 3ms (ActiveRecord: 0.1ms)
608
+  (0.0ms) rollback transaction
609
+ Connecting to database specified by database.yml
610
+  (0.2ms) begin transaction
611
+ Fixture Delete (0.1ms) DELETE FROM "phones"
612
+ Fixture Insert (0.1ms) INSERT 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)
613
+ Fixture Insert (0.0ms) 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
+ Fixture Insert (0.0ms) INSERT INTO "phones" ("number", "created_at", "updated_at", "id") VALUES ('972541234567', '2013-06-04 11:25:09', '2013-06-04 11:25:09', 512636273)
615
+ Fixture Insert (0.0ms) 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
+ Fixture Insert (0.0ms) INSERT 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)
617
+  (3.2ms) commit transaction
618
+  (0.1ms) begin transaction
619
+ Phone Load (1.4ms) SELECT "phones".* FROM "phones" WHERE "phones"."id" = ? LIMIT 1 [["id", 512636273]]
620
+  (0.1ms) SAVEPOINT active_record_1
621
+  (0.1ms) RELEASE SAVEPOINT active_record_1
622
+  (0.0ms) rollback transaction
623
+  (0.0ms) begin transaction
624
+  (0.0ms) SAVEPOINT active_record_1
625
+  (0.0ms) ROLLBACK TO SAVEPOINT active_record_1
626
+  (0.0ms) rollback transaction
627
+  (0.0ms) begin transaction
628
+  (0.0ms) SAVEPOINT active_record_1
629
+ SQL (0.7ms) 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
+  (0.0ms) RELEASE SAVEPOINT active_record_1
631
+  (0.1ms) rollback transaction
632
+  (0.0ms) begin transaction
633
+ Phone Load (0.0ms) SELECT "phones".* FROM "phones" WHERE "phones"."id" = ? LIMIT 1 [["id", 450723037]]
634
+  (0.0ms) SAVEPOINT active_record_1
635
+  (0.0ms) RELEASE SAVEPOINT active_record_1
636
+  (0.0ms) rollback transaction
637
+  (0.0ms) begin transaction
638
+ Phone Load (0.0ms) SELECT "phones".* FROM "phones" WHERE "phones"."id" = ? LIMIT 1 [["id", 23760034]]
639
+  (0.0ms) SAVEPOINT active_record_1
640
+  (0.0ms) ROLLBACK TO SAVEPOINT active_record_1
641
+  (0.0ms) rollback transaction
642
+  (0.0ms) begin transaction
643
+ Phone Load (0.0ms) SELECT "phones".* FROM "phones" WHERE "phones"."id" = ? LIMIT 1 [["id", 667262234]]
644
+  (0.0ms) SAVEPOINT active_record_1
645
+  (0.0ms) ROLLBACK TO SAVEPOINT active_record_1
646
+  (0.0ms) rollback transaction
647
+  (0.0ms) begin transaction
648
+ Phone Load (0.0ms) SELECT "phones".* FROM "phones" WHERE "phones"."id" = ? LIMIT 1 [["id", 703612349]]
649
+  (0.0ms) SAVEPOINT active_record_1
650
+  (0.0ms) ROLLBACK TO SAVEPOINT active_record_1
651
+  (0.0ms) rollback transaction
652
+  (0.1ms) begin transaction
653
+ Phone Load (0.1ms) SELECT "phones".* FROM "phones" WHERE "phones"."id" = ? LIMIT 1 [["id", 450723037]]
654
+  (0.1ms) SELECT COUNT(*) FROM "phones" 
655
+ Processing by PhonesController#create as HTML
656
+ Parameters: {"phone"=>{"number"=>"972541234567"}}
657
+  (0.0ms) SAVEPOINT active_record_1
658
+ SQL (0.2ms) 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]]
659
+  (0.0ms) RELEASE SAVEPOINT active_record_1
660
+ Redirected to http://test.host/phones/703612350
661
+ Completed 302 Found in 3ms (ActiveRecord: 0.3ms)
662
+  (0.0ms) SELECT COUNT(*) FROM "phones" 
663
+  (0.1ms) rollback transaction
664
+  (0.0ms) begin transaction
665
+ Phone Load (0.0ms) SELECT "phones".* FROM "phones" WHERE "phones"."id" = ? LIMIT 1 [["id", 450723037]]
666
+  (0.0ms) SELECT COUNT(*) FROM "phones" 
667
+ Processing by PhonesController#destroy as HTML
668
+ Parameters: {"id"=>"450723037"}
669
+ Phone Load (0.0ms) SELECT "phones".* FROM "phones" WHERE "phones"."id" = ? LIMIT 1 [["id", "450723037"]]
670
+  (0.0ms) SAVEPOINT active_record_1
671
+ SQL (0.1ms) DELETE FROM "phones" WHERE "phones"."id" = ? [["id", 450723037]]
672
+  (0.0ms) RELEASE SAVEPOINT active_record_1
673
+ Redirected to http://test.host/phones
674
+ Completed 302 Found in 1ms (ActiveRecord: 0.2ms)
675
+  (0.0ms) SELECT COUNT(*) FROM "phones"
676
+  (0.0ms) rollback transaction
677
+  (0.0ms) begin transaction
678
+ Phone Load (0.0ms) SELECT "phones".* FROM "phones" WHERE "phones"."id" = ? LIMIT 1 [["id", 450723037]]
679
+ Processing by PhonesController#edit as HTML
680
+ Parameters: {"id"=>"450723037"}
681
+ Phone Load (0.0ms) 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
+  (0.1ms) rollback transaction
685
+  (0.0ms) begin transaction
686
+ Phone Load (0.1ms) SELECT "phones".* FROM "phones" WHERE "phones"."id" = ? LIMIT 1 [["id", 450723037]]
687
+ Processing by PhonesController#index as HTML
688
+ Phone Load (0.1ms) SELECT "phones".* FROM "phones"
689
+ Completed 200 OK in 4ms (Views: 3.4ms | ActiveRecord: 0.1ms)
690
+  (0.0ms) rollback transaction
691
+  (0.0ms) begin transaction
692
+ Phone Load (0.0ms) SELECT "phones".* FROM "phones" WHERE "phones"."id" = ? LIMIT 1 [["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
+  (0.0ms) rollback transaction
697
+  (0.0ms) begin transaction
698
+ Phone Load (0.0ms) SELECT "phones".* FROM "phones" WHERE "phones"."id" = ? LIMIT 1 [["id", 450723037]]
699
+ Processing by PhonesController#show as HTML
700
+ Parameters: {"id"=>"450723037"}
701
+ Phone Load (0.0ms) SELECT "phones".* FROM "phones" WHERE "phones"."id" = ? LIMIT 1 [["id", "450723037"]]
702
+ Completed 200 OK in 2ms (Views: 1.3ms | ActiveRecord: 0.0ms)
703
+  (0.0ms) rollback transaction
704
+  (0.0ms) begin transaction
705
+ Phone Load (0.0ms) 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
+ Phone Load (0.0ms) SELECT "phones".* FROM "phones" WHERE "phones"."id" = ? LIMIT 1 [["id", "450723037"]]
709
+  (0.0ms) SAVEPOINT active_record_1
710
+  (0.0ms) RELEASE SAVEPOINT active_record_1
711
+ Redirected to http://test.host/phones/450723037
712
+ Completed 302 Found in 3ms (ActiveRecord: 0.1ms)
713
+  (0.0ms) rollback transaction
@@ -1,105 +1,175 @@
1
1
  require 'test_helper'
2
2
 
3
- class PhonelibTest < ActiveSupport::TestCase
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
- test "possible but not valid phone number" do
53
- phone = Phonelib.parse('9721234567')
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
- test "national method returns sanitized national when number invalid but possible" do
102
- phone = Phonelib.parse('9721234567')
103
- assert phone.national == '1234567'
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
@@ -1,6 +1,7 @@
1
1
  # Configure Rails Environment
2
2
  ENV["RAILS_ENV"] = "test"
3
3
 
4
+ require 'shoulda-context'
4
5
  require File.expand_path("../dummy/config/environment.rb", __FILE__)
5
6
  require "rails/test_help"
6
7
 
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.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-05-30 00:00:00.000000000 Z
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: &17731760 !ruby/object:Gem::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: *17731760
24
+ version_requirements: *16799660
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: sqlite3
27
- requirement: &17730980 !ruby/object:Gem::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: *17730980
35
+ version_requirements: *16798880
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: nokogiri
38
- requirement: &17730140 !ruby/object:Gem::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: *17730140
46
+ version_requirements: *16798100
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: pry
49
- requirement: &17729360 !ruby/object:Gem::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: *17729360
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: -3858765468631295667
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: -3858765468631295667
163
+ hash: -3279311756524952589
153
164
  requirements: []
154
165
  rubyforge_project:
155
166
  rubygems_version: 1.8.17