cadun 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/cadun/user.rb +9 -2
- data/lib/cadun/version.rb +1 -1
- data/spec/cadun/user_spec.rb +26 -2
- metadata +1 -1
data/lib/cadun/user.rb
CHANGED
@@ -2,7 +2,7 @@ module Cadun
|
|
2
2
|
class User
|
3
3
|
attr_reader :gateway
|
4
4
|
|
5
|
-
{ "id" => "
|
5
|
+
{ "id" => "user_id",
|
6
6
|
"nome" => "name",
|
7
7
|
"emailPrincipal" => "email",
|
8
8
|
"tipoUsuario" => "user_type",
|
@@ -10,10 +10,13 @@ module Cadun
|
|
10
10
|
"bairro" => "neighborhood",
|
11
11
|
"cidade/nome" => "city",
|
12
12
|
"estado/sigla" => "state",
|
13
|
-
"pais/nome" => "country"
|
13
|
+
"pais/nome" => "country",
|
14
|
+
"cep" => "zipcode" }.each do |path, method|
|
14
15
|
define_method(method) { gateway.content.xpath(path).text }
|
15
16
|
end
|
16
17
|
|
18
|
+
alias :id :user_id
|
19
|
+
|
17
20
|
def initialize(options = {})
|
18
21
|
@gateway = Gateway.new(options)
|
19
22
|
end
|
@@ -34,6 +37,10 @@ module Cadun
|
|
34
37
|
"#{telefoneCelularDdd} #{telefoneCelular}"
|
35
38
|
end
|
36
39
|
|
40
|
+
def to_hash
|
41
|
+
%w(user_id name email user_type gender neighborhood city state country address birthday phone mobile login cpf zipcode status).inject(Hash.new(0)) { |hash, method| hash[method.to_sym] = send(method); hash }
|
42
|
+
end
|
43
|
+
|
37
44
|
def method_missing(method)
|
38
45
|
gateway.content.xpath(method.to_s).text
|
39
46
|
end
|
data/lib/cadun/version.rb
CHANGED
data/spec/cadun/user_spec.rb
CHANGED
@@ -53,13 +53,15 @@ describe Cadun::User do
|
|
53
53
|
verify_method "country", "Brasil"
|
54
54
|
|
55
55
|
verify_method "user_type", "NAO_ASSINANTE"
|
56
|
+
|
57
|
+
verify_method "user_id", "21737810"
|
56
58
|
end
|
57
59
|
|
58
60
|
context "when the user id is given" do
|
59
|
-
subject { Cadun::User.new :user_id => "10001000"
|
61
|
+
subject { Cadun::User.new :user_id => "10001000" }
|
60
62
|
|
61
63
|
it "should load the gateway" do
|
62
|
-
mock(Cadun::Gateway).new(hash_including(:
|
64
|
+
mock(Cadun::Gateway).new(hash_including(:user_id => "10001000"))
|
63
65
|
subject
|
64
66
|
end
|
65
67
|
|
@@ -67,4 +69,26 @@ describe Cadun::User do
|
|
67
69
|
|
68
70
|
verify_method "name", "Guilherme Chico"
|
69
71
|
end
|
72
|
+
|
73
|
+
describe "#to_hash" do
|
74
|
+
subject { Cadun::User.new(:user_id => "10001000").to_hash }
|
75
|
+
|
76
|
+
specify { should include(:user_id => "10001000") }
|
77
|
+
specify { should include(:name => "Guilherme Chico") }
|
78
|
+
specify { should include(:email => "fab1@spam.la") }
|
79
|
+
specify { should include(:user_type => "NAO_ASSINANTE") }
|
80
|
+
specify { should include(:gender => "MASCULINO") }
|
81
|
+
specify { should include(:neighborhood => "Andaraí") }
|
82
|
+
specify { should include(:city => "Rio de Janeiro") }
|
83
|
+
specify { should include(:state => "RJ") }
|
84
|
+
specify { should include(:country => "Brasil") }
|
85
|
+
specify { should include(:address => "Rua Uruguai, 59") }
|
86
|
+
specify { should include(:birthday => Date.new(1983, 02, 22)) }
|
87
|
+
specify { should include(:phone => "21 22881060") }
|
88
|
+
specify { should include(:mobile => "21 99999999") }
|
89
|
+
specify { should include(:login => "fabricio_fab1") }
|
90
|
+
specify { should include(:cpf => "09532034765") }
|
91
|
+
specify { should include(:zipcode => "20510060") }
|
92
|
+
specify { should include(:status => "ATIVO") }
|
93
|
+
end
|
70
94
|
end
|