your_membership 1.1.0 → 1.1.1
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.
- checksums.yaml +4 -4
- data/.env +5 -0
- data/.gitignore +1 -0
- data/.rspec +1 -0
- data/CHANGELOG.md +10 -0
- data/README.md +12 -10
- data/lib/httparty/patch.rb +33 -33
- data/lib/your_membership/base.rb +197 -197
- data/lib/your_membership/commerce.rb +25 -25
- data/lib/your_membership/config.rb +41 -41
- data/lib/your_membership/convert.rb +24 -24
- data/lib/your_membership/error.rb +21 -21
- data/lib/your_membership/events.rb +60 -60
- data/lib/your_membership/feeds.rb +37 -37
- data/lib/your_membership/member.rb +399 -397
- data/lib/your_membership/members.rb +124 -124
- data/lib/your_membership/people.rb +38 -38
- data/lib/your_membership/profile.rb +92 -85
- data/lib/your_membership/sa.rb +6 -6
- data/lib/your_membership/sa_auth.rb +34 -34
- data/lib/your_membership/sa_certifications.rb +22 -22
- data/lib/your_membership/sa_commerce.rb +22 -22
- data/lib/your_membership/sa_events.rb +66 -66
- data/lib/your_membership/sa_export.rb +195 -195
- data/lib/your_membership/sa_groups.rb +30 -30
- data/lib/your_membership/sa_member.rb +49 -49
- data/lib/your_membership/sa_members.rb +180 -179
- data/lib/your_membership/sa_nonmembers.rb +41 -41
- data/lib/your_membership/sa_people.rb +92 -92
- data/lib/your_membership/session.rb +148 -152
- data/lib/your_membership/version.rb +1 -1
- data/spec/fixtures/vcr_cassettes/sa_members_all_getids_timestamp_multiple.yml +51 -0
- data/spec/fixtures/vcr_cassettes/sa_members_all_getids_timestamp_none.yml +51 -0
- data/spec/fixtures/vcr_cassettes/sa_members_all_getids_timestamp_single.yml +51 -0
- data/spec/lib/{profile_spec.rb → your_membership/profile_spec.rb} +232 -197
- data/spec/lib/your_membership/sa_members_spec.rb +38 -0
- data/spec/spec_helper.rb +101 -78
- data/your_membership.gemspec +4 -0
- metadata +85 -19
@@ -0,0 +1,51 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: https://api.yourmembership.com/
|
6
|
+
body:
|
7
|
+
encoding: UTF-8
|
8
|
+
string: |
|
9
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
10
|
+
<YourMembership>
|
11
|
+
<Version>2.00</Version>
|
12
|
+
<ApiKey><PRIVATE_KEY></ApiKey>
|
13
|
+
<SaPasscode><SA_PASSCODE></SaPasscode>
|
14
|
+
<CallID>10000</CallID>
|
15
|
+
<Call Method="Sa.Members.All.GetIDs">
|
16
|
+
<Timestamp>2015-12-02 15:54:11</Timestamp>
|
17
|
+
</Call>
|
18
|
+
</YourMembership>
|
19
|
+
headers:
|
20
|
+
Accept-Encoding:
|
21
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
22
|
+
Accept:
|
23
|
+
- "*/*"
|
24
|
+
User-Agent:
|
25
|
+
- Ruby
|
26
|
+
response:
|
27
|
+
status:
|
28
|
+
code: 200
|
29
|
+
message: OK
|
30
|
+
headers:
|
31
|
+
Cache-Control:
|
32
|
+
- private
|
33
|
+
Content-Length:
|
34
|
+
- '24051'
|
35
|
+
Content-Type:
|
36
|
+
- text/xml; Charset=utf-8
|
37
|
+
Set-Cookie:
|
38
|
+
- "<ASP_SESSION_ID>"
|
39
|
+
X-Powered-By:
|
40
|
+
- ASP.NET
|
41
|
+
Date:
|
42
|
+
- Wed, 16 Dec 2015 20:54:12 GMT
|
43
|
+
Connection:
|
44
|
+
- Keep-alive
|
45
|
+
body:
|
46
|
+
encoding: UTF-8
|
47
|
+
string: "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\r\n\r\n<YourMembership_Response>\r\n<ErrCode>0</ErrCode>\r\n<ExtendedErrorInfo></ExtendedErrorInfo>\r\n<Sa.Members.All.GetIDs>\r\n<ServerGmtBias>-5</ServerGmtBias>\r\n<ServerTime>2015-12-16
|
48
|
+
15:54:12</ServerTime>\r\n<Members>\r\n<ID>57EEB598-CB44-4D85-B0D6-377F393AF5B4</ID>\r\n<ID>1C0CE647-FAA5-4EB0-ADF0-5B669B36378E</ID>\r\n</Members>\r\n</Sa.Members.All.GetIDs>\r\n</YourMembership_Response>\r\n"
|
49
|
+
http_version:
|
50
|
+
recorded_at: Wed, 16 Dec 2015 20:54:12 GMT
|
51
|
+
recorded_with: VCR 3.0.0
|
@@ -0,0 +1,51 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: https://api.yourmembership.com/
|
6
|
+
body:
|
7
|
+
encoding: UTF-8
|
8
|
+
string: |
|
9
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
10
|
+
<YourMembership>
|
11
|
+
<Version>2.00</Version>
|
12
|
+
<ApiKey><PRIVATE_KEY></ApiKey>
|
13
|
+
<SaPasscode><SA_PASSCODE></SaPasscode>
|
14
|
+
<CallID>10001</CallID>
|
15
|
+
<Call Method="Sa.Members.All.GetIDs">
|
16
|
+
<Timestamp>2015-12-16 15:54:12</Timestamp>
|
17
|
+
</Call>
|
18
|
+
</YourMembership>
|
19
|
+
headers:
|
20
|
+
Accept-Encoding:
|
21
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
22
|
+
Accept:
|
23
|
+
- "*/*"
|
24
|
+
User-Agent:
|
25
|
+
- Ruby
|
26
|
+
response:
|
27
|
+
status:
|
28
|
+
code: 200
|
29
|
+
message: OK
|
30
|
+
headers:
|
31
|
+
Cache-Control:
|
32
|
+
- private
|
33
|
+
Content-Length:
|
34
|
+
- '314'
|
35
|
+
Content-Type:
|
36
|
+
- text/xml; Charset=utf-8
|
37
|
+
Set-Cookie:
|
38
|
+
- "<ASP_SESSION_ID>"
|
39
|
+
X-Powered-By:
|
40
|
+
- ASP.NET
|
41
|
+
Date:
|
42
|
+
- Wed, 16 Dec 2015 20:54:12 GMT
|
43
|
+
Connection:
|
44
|
+
- Keep-alive
|
45
|
+
body:
|
46
|
+
encoding: UTF-8
|
47
|
+
string: "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\r\n\r\n<YourMembership_Response>\r\n<ErrCode>0</ErrCode>\r\n<ExtendedErrorInfo></ExtendedErrorInfo>\r\n<Sa.Members.All.GetIDs>\r\n<ServerGmtBias>-5</ServerGmtBias>\r\n<ServerTime>2015-12-16
|
48
|
+
15:54:13</ServerTime>\r\n<Members></Members>\r\n</Sa.Members.All.GetIDs>\r\n</YourMembership_Response>\r\n"
|
49
|
+
http_version:
|
50
|
+
recorded_at: Wed, 16 Dec 2015 20:54:12 GMT
|
51
|
+
recorded_with: VCR 3.0.0
|
@@ -0,0 +1,51 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: https://api.yourmembership.com/
|
6
|
+
body:
|
7
|
+
encoding: UTF-8
|
8
|
+
string: |
|
9
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
10
|
+
<YourMembership>
|
11
|
+
<Version>2.00</Version>
|
12
|
+
<ApiKey><PRIVATE_KEY></ApiKey>
|
13
|
+
<SaPasscode><SA_PASSCODE></SaPasscode>
|
14
|
+
<CallID>10002</CallID>
|
15
|
+
<Call Method="Sa.Members.All.GetIDs">
|
16
|
+
<Timestamp>2015-12-06 15:54:12</Timestamp>
|
17
|
+
</Call>
|
18
|
+
</YourMembership>
|
19
|
+
headers:
|
20
|
+
Accept-Encoding:
|
21
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
22
|
+
Accept:
|
23
|
+
- "*/*"
|
24
|
+
User-Agent:
|
25
|
+
- Ruby
|
26
|
+
response:
|
27
|
+
status:
|
28
|
+
code: 200
|
29
|
+
message: OK
|
30
|
+
headers:
|
31
|
+
Cache-Control:
|
32
|
+
- private
|
33
|
+
Content-Length:
|
34
|
+
- '363'
|
35
|
+
Content-Type:
|
36
|
+
- text/xml; Charset=utf-8
|
37
|
+
Set-Cookie:
|
38
|
+
- "<ASP_SESSION_ID>"
|
39
|
+
X-Powered-By:
|
40
|
+
- ASP.NET
|
41
|
+
Date:
|
42
|
+
- Wed, 16 Dec 2015 20:54:12 GMT
|
43
|
+
Connection:
|
44
|
+
- Keep-alive
|
45
|
+
body:
|
46
|
+
encoding: UTF-8
|
47
|
+
string: "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\r\n\r\n<YourMembership_Response>\r\n<ErrCode>0</ErrCode>\r\n<ExtendedErrorInfo></ExtendedErrorInfo>\r\n<Sa.Members.All.GetIDs>\r\n<ServerGmtBias>-5</ServerGmtBias>\r\n<ServerTime>2015-12-16
|
48
|
+
15:54:13</ServerTime>\r\n<Members>\r\n<ID>F185B3A5-2ED9-424E-82AF-D918B4E604E4</ID>\r\n</Members>\r\n</Sa.Members.All.GetIDs>\r\n</YourMembership_Response>\r\n"
|
49
|
+
http_version:
|
50
|
+
recorded_at: Wed, 16 Dec 2015 20:54:13 GMT
|
51
|
+
recorded_with: VCR 3.0.0
|
@@ -1,197 +1,232 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
"
|
8
|
-
"
|
9
|
-
"
|
10
|
-
"
|
11
|
-
"
|
12
|
-
"
|
13
|
-
"
|
14
|
-
"
|
15
|
-
"
|
16
|
-
"
|
17
|
-
"
|
18
|
-
"
|
19
|
-
"
|
20
|
-
"
|
21
|
-
"
|
22
|
-
"
|
23
|
-
"
|
24
|
-
"
|
25
|
-
"
|
26
|
-
"
|
27
|
-
"
|
28
|
-
"
|
29
|
-
"
|
30
|
-
"
|
31
|
-
"
|
32
|
-
"
|
33
|
-
"
|
34
|
-
"
|
35
|
-
"
|
36
|
-
"
|
37
|
-
"
|
38
|
-
"
|
39
|
-
"
|
40
|
-
"
|
41
|
-
"
|
42
|
-
"
|
43
|
-
"
|
44
|
-
"
|
45
|
-
"
|
46
|
-
"
|
47
|
-
"
|
48
|
-
"
|
49
|
-
"
|
50
|
-
"
|
51
|
-
"
|
52
|
-
"
|
53
|
-
"
|
54
|
-
"
|
55
|
-
"
|
56
|
-
"
|
57
|
-
"
|
58
|
-
"
|
59
|
-
"
|
60
|
-
"
|
61
|
-
"
|
62
|
-
"
|
63
|
-
"
|
64
|
-
"
|
65
|
-
"
|
66
|
-
"
|
67
|
-
"
|
68
|
-
"
|
69
|
-
"
|
70
|
-
"
|
71
|
-
"
|
72
|
-
|
73
|
-
|
74
|
-
{"Values"=>{"Value"=>"
|
75
|
-
{"Values"=>{"Value"=>"
|
76
|
-
{"Values"=>{"Value"=>"North
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
profile
|
83
|
-
profile.data['
|
84
|
-
profile.data['
|
85
|
-
profile.data['
|
86
|
-
profile.data['Username'].should == 'ausername'
|
87
|
-
profile.data['Password'].should == 'apassword'
|
88
|
-
end
|
89
|
-
|
90
|
-
it "adds arbitrary keys when creating new profiles" do
|
91
|
-
profile_hash = {'foo' => 'bar'}
|
92
|
-
profile = YourMembership::Profile.create_new('afirstname', 'alastname', 'amembertypecode', 'ausername', nil, profile_hash)
|
93
|
-
profile.data.should include 'foo'
|
94
|
-
profile.data['foo'].should == 'bar'
|
95
|
-
end
|
96
|
-
|
97
|
-
it "adds arbitrary custom keys when creating new profiles" do
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
profile
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
profile
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
profile =
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
profile = YourMembership::Profile.new
|
152
|
-
|
153
|
-
expect profile.
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
profile
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe YourMembership::Profile do
|
4
|
+
before do
|
5
|
+
@sample_profile = {
|
6
|
+
"ID"=>"F8C2BEFD-GF37-5CBC-B750-487162B95CDF",
|
7
|
+
"WebsiteID"=>"16273406",
|
8
|
+
"PrimaryGroupCode"=>nil,
|
9
|
+
"IsMember"=>"1",
|
10
|
+
"IsNonMember"=>"0",
|
11
|
+
"Registered"=>"2014-06-12 14:53:30",
|
12
|
+
"LastUpdated"=>"2014-08-07 14:31:34",
|
13
|
+
"ImportID"=>"YM-40539-798958-4242",
|
14
|
+
"ConstituentID"=>nil,
|
15
|
+
"EmailAddr"=>"nflood@echonet.org",
|
16
|
+
"EmailBounced"=>"0",
|
17
|
+
"NamePrefix"=>"Mr",
|
18
|
+
"FirstName"=>"Nate",
|
19
|
+
"MiddleName"=>nil,
|
20
|
+
"LastName"=>"Flood",
|
21
|
+
"NameSuffix"=>nil,
|
22
|
+
"Nickname"=>"Nate Flood",
|
23
|
+
"Gender"=>"M",
|
24
|
+
"Birthdate"=>nil,
|
25
|
+
"MaritalStatus"=>nil,
|
26
|
+
"MaidenName"=>nil,
|
27
|
+
"SpouseName"=>nil,
|
28
|
+
"AnniversaryDate"=>nil,
|
29
|
+
"Employer"=>"ECHO INC.",
|
30
|
+
"Title"=>"Digital Media Specialist",
|
31
|
+
"Profession"=>nil,
|
32
|
+
"Membership"=>"ECHO Interns and Current Staff",
|
33
|
+
"MembershipExpiry"=>nil,
|
34
|
+
"MemberTypeCode"=>"ECHOstaff",
|
35
|
+
"Approved"=>"1",
|
36
|
+
"Suspended"=>"0",
|
37
|
+
"Username"=>"nflood",
|
38
|
+
"PasswordHash"=>"1E10A122BDB35AN022FEJF617BE14527E72KA26E",
|
39
|
+
"AltEmailAddr"=>nil,
|
40
|
+
"HomeAddrLines"=>nil,
|
41
|
+
"HomeCity"=>nil,
|
42
|
+
"HomeLocation"=>nil,
|
43
|
+
"HomePostalCode"=>nil,
|
44
|
+
"HomeCountry"=>nil,
|
45
|
+
"Website"=>nil,
|
46
|
+
"HomePhAreaCode"=>nil,
|
47
|
+
"HomePhone"=>nil,
|
48
|
+
"MobileAreaCode"=>nil,
|
49
|
+
"Mobile"=>nil,
|
50
|
+
"EmpAddrLines"=>"17391 Durrance Road",
|
51
|
+
"EmpCity"=>"North Fort Myers",
|
52
|
+
"EmpLocation"=>"Florida",
|
53
|
+
"EmpPostalCode"=>"33917",
|
54
|
+
"EmpCountry"=>"United States",
|
55
|
+
"BusinessWebsite"=>nil,
|
56
|
+
"EmpPhAreaCode"=>"239",
|
57
|
+
"EmpPhone"=>"567-3355",
|
58
|
+
"EmpFaxAreaCode"=>nil,
|
59
|
+
"EmpFax"=>nil,
|
60
|
+
"LastRenewalReminderSent"=>nil,
|
61
|
+
"GamificationPoints"=>"198",
|
62
|
+
"HeadshotImageURI"=>"http://c.yourmembership.com/sites/echocommunity.site-ym.com/photos/alumni/20140725_144857_16292.jpg",
|
63
|
+
"MasterID"=>nil,
|
64
|
+
"LastRenewalDate"=>"2014-06-12 14:53:00",
|
65
|
+
"ApprovalDate"=>"6/12/2014 2:54:19 PM",
|
66
|
+
"LastModifiedDate"=>"2014-08-07 14:31:34",
|
67
|
+
"QueuedForDelete"=>"0",
|
68
|
+
"QueuedForDeleteDate"=>nil,
|
69
|
+
"Latitude"=>"0",
|
70
|
+
"Longitude"=>"0",
|
71
|
+
"CustomFieldResponses"=>{
|
72
|
+
"CustomFieldResponse"=>[
|
73
|
+
{"Values"=>{"Value"=>"USA"}, "FieldCode"=>"Workingcountry", "Visibility"=>""},
|
74
|
+
{"Values"=>{"Value"=>"other"}, "FieldCode"=>"UserType", "Visibility"=>""},
|
75
|
+
{"Values"=>{"Value"=>"North America"}, "FieldCode"=>"region", "Visibility"=>""},
|
76
|
+
{"Values"=>{"Value"=>["North","South"]}, "FieldCode"=>"PCVenddate", "Visibility"=>""} ]
|
77
|
+
}
|
78
|
+
}
|
79
|
+
end
|
80
|
+
it "accepts and sets required parameters for new profiles" do
|
81
|
+
profile = YourMembership::Profile.create_new('afirstname', 'alastname', 'amembertypecode', 'aemail', 'ausername', 'apassword', {})
|
82
|
+
profile.data['FirstName'].should == 'afirstname'
|
83
|
+
profile.data['LastName'].should == 'alastname'
|
84
|
+
profile.data['MemberTypeCode'].should == 'amembertypecode'
|
85
|
+
profile.data['EmailAddr'].should == 'aemail'
|
86
|
+
profile.data['Username'].should == 'ausername'
|
87
|
+
profile.data['Password'].should == 'apassword'
|
88
|
+
end
|
89
|
+
|
90
|
+
it "adds arbitrary keys when creating new profiles" do
|
91
|
+
profile_hash = {'foo' => 'bar'}
|
92
|
+
profile = YourMembership::Profile.create_new('afirstname', 'alastname', 'amembertypecode', 'aemail', 'ausername', nil, profile_hash)
|
93
|
+
profile.data.should include 'foo'
|
94
|
+
profile.data['foo'].should == 'bar'
|
95
|
+
end
|
96
|
+
|
97
|
+
it "adds arbitrary custom keys when creating new profiles" do
|
98
|
+
profile_hash = {
|
99
|
+
'CustomFieldResponses' => {
|
100
|
+
'CustomFieldResponse' => [{
|
101
|
+
'FieldCode' => 'foo',
|
102
|
+
'Values' => {
|
103
|
+
'Value' => 'bar'
|
104
|
+
}
|
105
|
+
}]
|
106
|
+
}
|
107
|
+
}
|
108
|
+
profile = YourMembership::Profile.create_new('afirstname', 'alastname', 'amembertypecode', 'aemail', 'ausername', nil, profile_hash)
|
109
|
+
profile.custom_data.should include 'foo'
|
110
|
+
profile.custom_data['foo'].should == 'bar'
|
111
|
+
end
|
112
|
+
|
113
|
+
it "creates an object based on a profile hash" do
|
114
|
+
profile = YourMembership::Profile.new(@sample_profile)
|
115
|
+
profile.data.should include 'FirstName'
|
116
|
+
end
|
117
|
+
|
118
|
+
it "adds arbitrary keys when creating based on a profile hash" do
|
119
|
+
profile_hash = {'foo' => 'bar'}
|
120
|
+
profile = YourMembership::Profile.new(profile_hash)
|
121
|
+
profile.data.should include 'foo'
|
122
|
+
profile.data['foo'].should == 'bar'
|
123
|
+
end
|
124
|
+
|
125
|
+
it "returns the output hash when asked" do
|
126
|
+
profile_hash = {'foo' => 'bar'}
|
127
|
+
profile = YourMembership::Profile.new(profile_hash)
|
128
|
+
profile.to_h.should be_a(Hash)
|
129
|
+
profile.to_h.should include 'foo'
|
130
|
+
end
|
131
|
+
|
132
|
+
it "does not return nil values in the output hash" do
|
133
|
+
profile_hash = {'foo' => 'bar', 'far' => nil}
|
134
|
+
profile = YourMembership::Profile.new(profile_hash)
|
135
|
+
profile.to_h.should include 'foo'
|
136
|
+
profile.to_h.should_not include 'far'
|
137
|
+
end
|
138
|
+
|
139
|
+
it "can be manipulated directly through the data attribute" do
|
140
|
+
profile_hash = {'foo' => 'bar'}
|
141
|
+
profile = YourMembership::Profile.new(profile_hash)
|
142
|
+
expect {profile.data['foo'] = 'baz'}.to change{profile.data['foo']}.from('bar').to('baz')
|
143
|
+
end
|
144
|
+
|
145
|
+
it "has a custom_data attribute" do
|
146
|
+
profile = YourMembership::Profile.new
|
147
|
+
expect profile.should respond_to 'custom_data'
|
148
|
+
end
|
149
|
+
|
150
|
+
it "can be manipulated directly through the custom data attribute" do
|
151
|
+
profile = YourMembership::Profile.new
|
152
|
+
profile.custom_data['foo'] = 'bar'
|
153
|
+
expect profile.custom_data.should include 'foo'
|
154
|
+
expect profile.custom_data['foo'].should == 'bar'
|
155
|
+
expect {profile.custom_data['foo'] = 'baz'}.to change{profile.custom_data['foo']}.from('bar').to('baz')
|
156
|
+
end
|
157
|
+
|
158
|
+
it "adds a 'CustomFieldResponses' key as a hash" do
|
159
|
+
profile_hash = {'foo' => 'bar'}
|
160
|
+
profile = YourMembership::Profile.new(profile_hash)
|
161
|
+
expect profile.to_h.should include 'CustomFieldResponses'
|
162
|
+
expect profile.to_h['CustomFieldResponses'].should be_a(Hash)
|
163
|
+
end
|
164
|
+
|
165
|
+
it "contains custom_data in the 'CustomFieldResponses' key hash" do
|
166
|
+
profile = YourMembership::Profile.new
|
167
|
+
profile.custom_data['foo'] = 'bar'
|
168
|
+
expect profile.to_h['CustomFieldResponses'].should include 'foo'
|
169
|
+
expect profile.to_h['CustomFieldResponses']['foo'].should == 'bar'
|
170
|
+
end
|
171
|
+
|
172
|
+
it "accepts strings as custom data" do
|
173
|
+
profile = YourMembership::Profile.new
|
174
|
+
profile.custom_data['foo'] = 'bar'
|
175
|
+
expect profile.to_h['CustomFieldResponses']['foo'].should be_a(String)
|
176
|
+
end
|
177
|
+
|
178
|
+
it "accepts arrays as custom data" do
|
179
|
+
profile = YourMembership::Profile.new
|
180
|
+
profile.custom_data['foo'] = ['bar', 'bat', 'baz']
|
181
|
+
expect profile.to_h['CustomFieldResponses']['foo'].should be_a(Array)
|
182
|
+
expect profile.to_h['CustomFieldResponses']['foo'].should include 'baz'
|
183
|
+
end
|
184
|
+
|
185
|
+
it "does not contain nil keys in the 'CustomFieldResponses'" do
|
186
|
+
profile = YourMembership::Profile.new
|
187
|
+
profile.custom_data['foo'] = nil
|
188
|
+
expect profile.to_h['CustomFieldResponses'].should_not include 'foo'
|
189
|
+
end
|
190
|
+
|
191
|
+
it "does not include 'CustomFieldResponses' in the data hash when creating from a profile hash" do
|
192
|
+
profile = YourMembership::Profile.new(@sample_profile)
|
193
|
+
profile.data.should_not include 'CustomFieldResponses'
|
194
|
+
end
|
195
|
+
|
196
|
+
it "puts 'CustomFieldResponses' into the custom_data hash when creating from a profile hash" do
|
197
|
+
profile = YourMembership::Profile.new(@sample_profile)
|
198
|
+
profile.custom_data.should include 'Workingcountry'
|
199
|
+
end
|
200
|
+
|
201
|
+
it "converts 'CustomFieldResponse' values to strings or arrays" do
|
202
|
+
profile = YourMembership::Profile.new(@sample_profile)
|
203
|
+
profile.custom_data.should include 'Workingcountry'
|
204
|
+
profile.custom_data['Workingcountry'].should == "USA"
|
205
|
+
end
|
206
|
+
|
207
|
+
describe 'when there is a single CustomFieldResponse' do
|
208
|
+
it 'parses correctly' do
|
209
|
+
odd_data = @sample_profile.clone
|
210
|
+
odd_data['CustomFieldResponses'] = {
|
211
|
+
"CustomFieldResponse" => {
|
212
|
+
"Values" => {
|
213
|
+
"Value" => "None"
|
214
|
+
},
|
215
|
+
"FieldCode" => "Foundation",
|
216
|
+
"Visibility" => ""
|
217
|
+
}
|
218
|
+
}
|
219
|
+
profile = YourMembership::Profile.new(odd_data)
|
220
|
+
expect(profile.custom_data['Foundation']).to eq('None')
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
describe 'when there is a single CustomFieldResponse' do
|
225
|
+
it 'parses correctly' do
|
226
|
+
data = @sample_profile.clone
|
227
|
+
data['CustomFieldResponses'] = nil
|
228
|
+
profile = YourMembership::Profile.new(data)
|
229
|
+
expect(profile.custom_data).to be_empty
|
230
|
+
end
|
231
|
+
end
|
232
|
+
end
|