mosaic-lyris 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +3 -0
- data/README +4 -0
- data/Rakefile +31 -0
- data/VERSION +1 -0
- data/init.rb +4 -0
- data/lib/lyris.rb +2 -0
- data/lib/mosaic/lyris.rb +12 -0
- data/lib/mosaic/lyris/demographic.rb +65 -0
- data/lib/mosaic/lyris/filter.rb +6 -0
- data/lib/mosaic/lyris/list.rb +73 -0
- data/lib/mosaic/lyris/message.rb +95 -0
- data/lib/mosaic/lyris/object.rb +227 -0
- data/lib/mosaic/lyris/partner.rb +6 -0
- data/lib/mosaic/lyris/record.rb +101 -0
- data/lib/mosaic/lyris/trigger.rb +113 -0
- data/lib/mosaic/lyris/upload.rb +89 -0
- data/lib/mosaic/lyris_mailer.rb +102 -0
- data/mosaic-lyris.gemspec +143 -0
- data/test/demographic_test.rb +176 -0
- data/test/filter_test.rb +6 -0
- data/test/http_responder.rb +88 -0
- data/test/list_test.rb +49 -0
- data/test/message_test.rb +6 -0
- data/test/partner_test.rb +6 -0
- data/test/record_test.rb +177 -0
- data/test/responses/demographic/add_error_name_already_exists.xml +2 -0
- data/test/responses/demographic/add_success_12345.xml +2 -0
- data/test/responses/demographic/query_all_success.xml +19 -0
- data/test/responses/demographic/query_enabled_details_success.xml +12 -0
- data/test/responses/demographic/query_enabled_success.xml +13 -0
- data/test/responses/list/add_error_name_already_exists.xml +2 -0
- data/test/responses/list/add_success_12345.xml +2 -0
- data/test/responses/list/delete_error_not_found_99999.xml +2 -0
- data/test/responses/list/delete_success_12345.xml +2 -0
- data/test/responses/list/query_list_data_success.xml +20 -0
- data/test/responses/record/add_error_email_already_exists.xml +2 -0
- data/test/responses/record/add_success.xml +2 -0
- data/test/responses/record/query_all_success.xml +94 -0
- data/test/responses/record/query_all_success_empty.xml +2 -0
- data/test/responses/record/query_all_success_page_1.xml +54 -0
- data/test/responses/record/query_all_success_page_2.xml +34 -0
- data/test/responses/record/query_all_success_page_3.xml +14 -0
- data/test/responses/record/query_email_error_not_found.xml +2 -0
- data/test/responses/record/query_email_success_active.xml +14 -0
- data/test/responses/record/query_email_success_admin_trashed.xml +14 -0
- data/test/responses/record/query_email_success_bounced.xml +14 -0
- data/test/responses/record/query_email_success_unsubscribed.xml +14 -0
- data/test/responses/record/update_error_not_found.xml +2 -0
- data/test/responses/record/update_success.xml +2 -0
- data/test/responses/triggers/fire_error_invalid_recipients.xml +2 -0
- data/test/responses/triggers/fire_error_invalid_trigger_id.xml +2 -0
- data/test/responses/triggers/fire_success.xml +2 -0
- data/test/test_helper.rb +68 -0
- data/test/trigger_test.rb +45 -0
- metadata +342 -0
@@ -0,0 +1,176 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__),'test_helper')
|
2
|
+
|
3
|
+
class TestDemographic < Test::Unit::TestCase
|
4
|
+
def test_add_duplicate
|
5
|
+
assert_raise Mosaic::Lyris::Error do
|
6
|
+
demographic = Mosaic::Lyris::Demographic.add :text, 'duplicate text', :list_id => 1
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_add_checkbox
|
11
|
+
demographic = Mosaic::Lyris::Demographic.add :checkbox, 'new checkbox', :list_id => 1, :enabled => true
|
12
|
+
assert_instance_of Mosaic::Lyris::Demographic, demographic
|
13
|
+
assert_equal 1, demographic.list_id
|
14
|
+
assert_equal 12345, demographic.id
|
15
|
+
assert_equal :checkbox, demographic.type
|
16
|
+
assert_equal 'new checkbox', demographic.name
|
17
|
+
assert demographic.enabled, 'demographic is not enabled'
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_add_date
|
21
|
+
demographic = Mosaic::Lyris::Demographic.add :date, 'new date', :list_id => 1, :enabled => true
|
22
|
+
assert_instance_of Mosaic::Lyris::Demographic, demographic
|
23
|
+
assert_equal 1, demographic.list_id
|
24
|
+
assert_equal 12345, demographic.id
|
25
|
+
assert_equal :date, demographic.type
|
26
|
+
assert_equal 'new date', demographic.name
|
27
|
+
assert demographic.enabled, 'demographic is not enabled'
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_add_multiple_checkbox
|
31
|
+
demographic = Mosaic::Lyris::Demographic.add :multiple_checkbox, 'new multiple checkbox', :list_id => 1, :options => %w(one two three four five), :enabled => true
|
32
|
+
assert_instance_of Mosaic::Lyris::Demographic, demographic
|
33
|
+
assert_equal 1, demographic.list_id
|
34
|
+
assert_equal 12345, demographic.id
|
35
|
+
assert_equal :multiple_checkbox, demographic.type
|
36
|
+
assert_equal 'new multiple checkbox', demographic.name
|
37
|
+
assert demographic.enabled, 'demographic is not enabled'
|
38
|
+
assert_equal %w(one two three four five), demographic.options
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_add_multiple_select_list
|
42
|
+
demographic = Mosaic::Lyris::Demographic.add :multiple_select_list, 'new multiple select list', :list_id => 1, :options => %w(one two three four five six seven eight nine ten), :size => 4, :enabled => true
|
43
|
+
assert_instance_of Mosaic::Lyris::Demographic, demographic
|
44
|
+
assert_equal 1, demographic.list_id
|
45
|
+
assert_equal 12345, demographic.id
|
46
|
+
assert_equal :multiple_select_list, demographic.type
|
47
|
+
assert_equal 'new multiple select list', demographic.name
|
48
|
+
assert demographic.enabled, 'demographic is not enabled'
|
49
|
+
assert_equal %w(one two three four five six seven eight nine ten), demographic.options
|
50
|
+
assert_equal 4, demographic.size
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_add_radio_button
|
54
|
+
demographic = Mosaic::Lyris::Demographic.add :radio_button, 'new radio button', :list_id => 1, :options => %w(one two three), :enabled => true
|
55
|
+
assert_instance_of Mosaic::Lyris::Demographic, demographic
|
56
|
+
assert_equal 1, demographic.list_id
|
57
|
+
assert_equal 12345, demographic.id
|
58
|
+
assert_equal :radio_button, demographic.type
|
59
|
+
assert_equal 'new radio button', demographic.name
|
60
|
+
assert demographic.enabled, 'demographic is not enabled'
|
61
|
+
assert_equal %w(one two three), demographic.options
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_add_select_list
|
65
|
+
demographic = Mosaic::Lyris::Demographic.add :select_list, 'new select list', :list_id => 1, :options => %w(one two three four five six seven eight), :size => 4, :enabled => true
|
66
|
+
assert_instance_of Mosaic::Lyris::Demographic, demographic
|
67
|
+
assert_equal 1, demographic.list_id
|
68
|
+
assert_equal 12345, demographic.id
|
69
|
+
assert_equal :select_list, demographic.type
|
70
|
+
assert_equal 'new select list', demographic.name
|
71
|
+
assert demographic.enabled, 'demographic is not enabled'
|
72
|
+
assert_equal %w(one two three four five six seven eight), demographic.options
|
73
|
+
assert_equal 4, demographic.size
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_add_text
|
77
|
+
demographic = Mosaic::Lyris::Demographic.add :text, 'new text', :list_id => 1, :enabled => true
|
78
|
+
assert_instance_of Mosaic::Lyris::Demographic, demographic
|
79
|
+
assert_equal 1, demographic.list_id
|
80
|
+
assert_equal 12345, demographic.id
|
81
|
+
assert_equal :text, demographic.type
|
82
|
+
assert_equal 'new text', demographic.name
|
83
|
+
assert demographic.enabled, 'demographic is not enabled'
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_add_textarea
|
87
|
+
demographic = Mosaic::Lyris::Demographic.add :textarea, 'new textarea', :list_id => 1, :enabled => true
|
88
|
+
assert_instance_of Mosaic::Lyris::Demographic, demographic
|
89
|
+
assert_equal 1, demographic.list_id
|
90
|
+
assert_equal 12345, demographic.id
|
91
|
+
assert_equal :textarea, demographic.type
|
92
|
+
assert_equal 'new textarea', demographic.name
|
93
|
+
assert demographic.enabled, 'demographic is not enabled'
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_bad_query
|
97
|
+
assert_raise ArgumentError do
|
98
|
+
demographics = Mosaic::Lyris::Demographic.query(:bad, :list_id => 1)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_bad_type
|
103
|
+
assert_raise ArgumentError do
|
104
|
+
demographic = Mosaic::Lyris::Demographic.add :bad, 'bad type', :list_id => 1, :enabled => true
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_invalid_options
|
109
|
+
assert_raise ArgumentError do
|
110
|
+
demographic = Mosaic::Lyris::Demographic.add :text, 'invalid options', :list_id => 1, :options => %w(one two three), :enabled => true
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def test_invalid_size
|
115
|
+
assert_raise ArgumentError do
|
116
|
+
demographic = Mosaic::Lyris::Demographic.add :text, 'invalid options', :list_id => 1, :size => 3, :enabled => true
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
def test_missing_options
|
121
|
+
assert_raise ArgumentError do
|
122
|
+
demographic = Mosaic::Lyris::Demographic.add :select_list, 'missing options', :list_id => 1, :enabled => true
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
def test_query_all
|
127
|
+
demographics = Mosaic::Lyris::Demographic.query(:all, :list_id => 1)
|
128
|
+
assert_instance_of Array, demographics
|
129
|
+
assert_equal 16, demographics.size
|
130
|
+
demographics.each_with_index do |d,i|
|
131
|
+
assert_instance_of Mosaic::Lyris::Demographic, d
|
132
|
+
assert_equal 1, d.list_id
|
133
|
+
assert_equal [(1..8).to_a,(11..18).to_a].flatten[i], d.id
|
134
|
+
assert_equal [:checkbox, :date, :multiple_checkbox, :multiple_select_list, :radio_button, :select_list, :text, :textarea, :checkbox, :date, :multiple_checkbox, :multiple_select_list, :radio_button, :select_list, :text, :textarea][i], d.type
|
135
|
+
assert_equal ['enabled checkbox', 'enabled date', 'enabled multiple checkbox', 'enabled multiple select list', 'enabled radio button', 'enabled select list', 'enabled text', 'enabled textarea', 'disabled checkbox', 'disabled date', 'disabled multiple checkbox', 'disabled multiple select list', 'disabled radio button', 'disabled select list', 'disabled text', 'disabled textarea'][i], d.name
|
136
|
+
assert_equal i < 8, d.enabled
|
137
|
+
assert_equal 'Custom', d.group
|
138
|
+
assert_nil d.options
|
139
|
+
assert_nil d.size
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
def test_query_enabled
|
144
|
+
demographics = Mosaic::Lyris::Demographic.query(:enabled, :list_id => 1)
|
145
|
+
assert_instance_of Array, demographics
|
146
|
+
assert_equal 9, demographics.size
|
147
|
+
demographics.each_with_index do |d,i|
|
148
|
+
assert_instance_of Mosaic::Lyris::Demographic, d
|
149
|
+
assert_equal 1, d.list_id
|
150
|
+
assert_equal i, d.id
|
151
|
+
assert_equal [:email, :checkbox, :date, :multiple_checkbox, :multiple_select_list, :radio_button, :select_list, :text, :textarea, :checkbox, :date, :multiple_checkbox, :multiple_select_list, :radio_button, :select_list, :text, :textarea][i], d.type
|
152
|
+
assert_equal ['EMAIL_ADDRESS', 'enabled checkbox', 'enabled date', 'enabled multiple checkbox', 'enabled multiple select list', 'enabled radio button', 'enabled select list', 'enabled text', 'enabled textarea'][i], d.name
|
153
|
+
assert d.enabled, "'#{d.name}' demographic should be enabled"
|
154
|
+
assert_nil d.group
|
155
|
+
assert_nil d.options
|
156
|
+
assert_nil d.size
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
def test_query_enabled_details
|
161
|
+
demographics = Mosaic::Lyris::Demographic.query(:enabled_details, :list_id => 1)
|
162
|
+
assert_instance_of Array, demographics
|
163
|
+
assert_equal 8, demographics.size
|
164
|
+
demographics.each_with_index do |d,i|
|
165
|
+
assert_instance_of Mosaic::Lyris::Demographic, d
|
166
|
+
assert_equal 1, d.list_id
|
167
|
+
assert_equal i+1, d.id
|
168
|
+
assert_equal [:checkbox, :date, :multiple_checkbox, :multiple_select_list, :radio_button, :select_list, :text, :textarea][i], d.type
|
169
|
+
assert_equal ['enabled checkbox', 'enabled date', 'enabled multiple checkbox', 'enabled multiple select list', 'enabled radio button', 'enabled select list', 'enabled text', 'enabled textarea'][i], d.name
|
170
|
+
assert d.enabled, "'#{d.name}' demographic should be enabled"
|
171
|
+
assert_nil d.group
|
172
|
+
assert_equal [nil, nil, %w(one two three four five), %w(one two three four five six seven eight nine ten), %w(one two three), %w(one two three four five six seven eight)][i], d.options
|
173
|
+
assert_nil d.size
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
data/test/filter_test.rb
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
|
3
|
+
module Net
|
4
|
+
class HTTPOK
|
5
|
+
def set_body(body)
|
6
|
+
@read = true
|
7
|
+
@body = body
|
8
|
+
self
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.with_body(body)
|
12
|
+
new('1.1','200','OK').set_body(body)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class HTTP
|
17
|
+
def request_with_capture(req, body = nil, &block)
|
18
|
+
response = request_without_capture(req, body, &block)
|
19
|
+
File.open(@capture_response, "w") do |file|
|
20
|
+
file.write response.body
|
21
|
+
end if @capture_response
|
22
|
+
response
|
23
|
+
end
|
24
|
+
alias_method :request_without_capture, :request
|
25
|
+
alias_method :request, :request_with_capture
|
26
|
+
|
27
|
+
def request_with_http_fixtures(req, body = nil, &block)
|
28
|
+
if response_body = self.class.response_for(req.method, req.path, req.body)
|
29
|
+
HTTPOK.with_body(response_body)
|
30
|
+
else
|
31
|
+
raise "HTTP requests are blocked!" if self.class.block_requests?
|
32
|
+
request_without_http_fixtures(req, body, &block)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
alias_method :request_without_http_fixtures, :request
|
36
|
+
alias_method :request, :request_with_http_fixtures
|
37
|
+
|
38
|
+
class << self
|
39
|
+
def block_requests(value = true)
|
40
|
+
@block_requests = value
|
41
|
+
end
|
42
|
+
|
43
|
+
def block_requests?
|
44
|
+
@block_requests
|
45
|
+
end
|
46
|
+
|
47
|
+
def capture_response(to = true)
|
48
|
+
@capture_response = (to == true) ? "capture.log" : to
|
49
|
+
end
|
50
|
+
|
51
|
+
def get_form_data(body)
|
52
|
+
body.split('&').inject({}) do |data,parameter|
|
53
|
+
name, value = parameter.split('=')
|
54
|
+
data[urldecode(name)] = urldecode(value)
|
55
|
+
data
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def respond_to(method, path, response_file, request_conditions = nil)
|
60
|
+
responses_by_method_and_path(method, path) << [request_conditions,File.read(response_file)]
|
61
|
+
end
|
62
|
+
|
63
|
+
def response_for(method, path, body)
|
64
|
+
data = get_form_data(body)
|
65
|
+
responses_by_method_and_path(method, path).each do |request_conditions,response_body|
|
66
|
+
return response_body if request_conditions.nil? || request_conditions.all? { |(k,v)| v === data[k.to_s] }
|
67
|
+
end
|
68
|
+
nil
|
69
|
+
end
|
70
|
+
|
71
|
+
def responses
|
72
|
+
@responses ||= {}
|
73
|
+
end
|
74
|
+
|
75
|
+
def responses_by_method(method)
|
76
|
+
responses[method.to_s.upcase] ||= {}
|
77
|
+
end
|
78
|
+
|
79
|
+
def responses_by_method_and_path(method, path)
|
80
|
+
responses_by_method(method)[path.to_s.downcase] ||= []
|
81
|
+
end
|
82
|
+
|
83
|
+
def urldecode(str)
|
84
|
+
str.gsub(/%([0-9a-f]{2})/) { |s| $1.hex.chr }
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
data/test/list_test.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__),'test_helper')
|
2
|
+
|
3
|
+
class TestList < Test::Unit::TestCase
|
4
|
+
def test_add
|
5
|
+
list = Mosaic::Lyris::List.add 'new list'
|
6
|
+
assert_instance_of Mosaic::Lyris::List, list
|
7
|
+
assert_equal 12345, list.id
|
8
|
+
assert_equal 'new list', list.name
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_add_duplicate
|
12
|
+
assert_raise Mosaic::Lyris::Error do
|
13
|
+
list = Mosaic::Lyris::List.add 'duplicate list'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_bad_query
|
18
|
+
assert_raise ArgumentError do
|
19
|
+
lists = Mosaic::Lyris::List.query(:bad)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_delete
|
24
|
+
list = Mosaic::Lyris::List.delete 12345
|
25
|
+
assert_instance_of Mosaic::Lyris::List, list
|
26
|
+
assert_equal 12345, list.id
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_delete_not_found
|
30
|
+
assert_raise Mosaic::Lyris::Error do
|
31
|
+
Mosaic::Lyris::List.delete 99999
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_query_all
|
36
|
+
lists = Mosaic::Lyris::List.query(:all)
|
37
|
+
assert_instance_of Array, lists
|
38
|
+
assert_equal 2, lists.size
|
39
|
+
lists.each_with_index do |l,i|
|
40
|
+
assert_instance_of Mosaic::Lyris::List, l
|
41
|
+
assert_equal i+1, l.id
|
42
|
+
assert_equal ['list one','list two'][i], l.name
|
43
|
+
assert_equal [Date.new(2001,1,1),Date.new(2002,2,2)][i], l.last_sent
|
44
|
+
assert_equal [1111,2222][i], l.members
|
45
|
+
assert_equal [11,22][i], l.messages
|
46
|
+
assert_equal [Time.utc(2001,1,1,1,1,1,0),Time.utc(2002,2,2,2,2,2,0)][i], l.cache_time
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/test/record_test.rb
ADDED
@@ -0,0 +1,177 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__),'test_helper')
|
2
|
+
|
3
|
+
class TestRecord < Test::Unit::TestCase
|
4
|
+
RECORDS = [
|
5
|
+
{ :email => 'one@one.not', :proof => true, :trashed => false, :state => 'active' },
|
6
|
+
{ :email => 'two@two.not', :proof => true, :trashed => false, :state => 'active' },
|
7
|
+
{ :email => 'three@three.not', :proof => true, :trashed => false, :state => 'active' },
|
8
|
+
{ :email => 'four@four.not', :proof => true, :trashed => false, :state => 'active' },
|
9
|
+
{ :email => 'five@five.not', :trashed => false, :state => 'active' },
|
10
|
+
{ :email => 'six@six.not', :trashed => true, :state => 'admin', :statedate => Date.new(2006,6,1) },
|
11
|
+
{ :email => 'seven@seven.not', :trashed => true, :state => 'unsubscribed', :statedate => Date.new(2007,7,1) },
|
12
|
+
{ :email => 'eight@eight.not', :trashed => true, :state => 'bounced', :statedate => Date.new(2008,8,1) },
|
13
|
+
{ :email => 'nine@nine.not', :trashed => false, :state => 'active' },
|
14
|
+
{ :email => 'ten@ten.not', :trashed => false, :state => 'active' }
|
15
|
+
]
|
16
|
+
|
17
|
+
DEMOGRAPHICS = [
|
18
|
+
{ 1 => 'on', 2 => '01/02/03', 3 => %w(one three), 4 => %w(two four), 5 => 'three', 6 => 'six', 7 => 'value for every demographic', 8 => 'the date value in demographic 2 should be Jan 2, 2003' },
|
19
|
+
{ 1 => 'on', 2 => '02/22/22', 5 => 'three', 6 => 'six', 7 => 'no value for multiple selection demographics', 8 => 'the date value in demographic 2 should be Feb 22, 1922' },
|
20
|
+
{ 1 => 'on', 2 => '03/03/33', 3 => %w(one three), 4 => %w(two four), 5 => 'three', 6 => 'six', 7 => 'every attribute enabled', 8 => 'the date value in demographic 2 should be Mar 3, 1933' },
|
21
|
+
nil,
|
22
|
+
{ 7 => 'active' },
|
23
|
+
{ 7 => 'trashed by administrator' },
|
24
|
+
{ 7 => 'unsubscribed' },
|
25
|
+
{ 7 => 'bounced' },
|
26
|
+
]
|
27
|
+
|
28
|
+
def test_add
|
29
|
+
record = Mosaic::Lyris::Record.add 'new@email.not', :list_id => 1, :demographics => DEMOGRAPHICS[0]
|
30
|
+
assert_instance_of Mosaic::Lyris::Record, record
|
31
|
+
assert_equal 'abcdef1967', record.id
|
32
|
+
assert_equal 'new@email.not', record.email
|
33
|
+
assert_equal nil, record.proof
|
34
|
+
assert_equal false, record.trashed
|
35
|
+
assert_equal 'active', record.state
|
36
|
+
assert_equal nil, record.statedate
|
37
|
+
assert_equal DEMOGRAPHICS[0], record.demographics
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_add_duplicate
|
41
|
+
assert_raise Mosaic::Lyris::Error do
|
42
|
+
record = Mosaic::Lyris::Record.add 'duplicate@email.not', :list_id => 1
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_bad_query
|
47
|
+
assert_raise ArgumentError do
|
48
|
+
records = Mosaic::Lyris::Record.query(:bad, :list_id => 1)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_update
|
53
|
+
record = Mosaic::Lyris::Record.update 'active@email.not', :list_id => 1, :state => 'unsubscribed'
|
54
|
+
assert_instance_of Mosaic::Lyris::Record, record
|
55
|
+
assert_equal 'abcdef1111', record.id
|
56
|
+
assert_equal 'active@email.not', record.email
|
57
|
+
assert_equal true, record.trashed
|
58
|
+
assert_equal 'unsubscribed', record.state
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_update_email
|
62
|
+
record = Mosaic::Lyris::Record.update 'active@email.not', :list_id => 1, :email => 'updated@email.not'
|
63
|
+
assert_instance_of Mosaic::Lyris::Record, record
|
64
|
+
assert_equal 'abcdef1111', record.id
|
65
|
+
assert_equal 'updated@email.not', record.email
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_update_not_found
|
69
|
+
assert_raise Mosaic::Lyris::Error do
|
70
|
+
record = Mosaic::Lyris::Record.update 'missing@email.not', :list_id => 1
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_query_all
|
75
|
+
records = Mosaic::Lyris::Record.query(:all, :list_id => 1)
|
76
|
+
assert_instance_of Array, records
|
77
|
+
assert_equal 10, records.size
|
78
|
+
records.each_with_index do |r,i|
|
79
|
+
assert_instance_of Mosaic::Lyris::Record, r
|
80
|
+
assert_equal 'abcdef%04d' % (i+1), r.id
|
81
|
+
assert_equal RECORDS[i][:email], r.email
|
82
|
+
assert_equal RECORDS[i][:proof], r.proof
|
83
|
+
assert_equal RECORDS[i][:trashed], r.trashed
|
84
|
+
assert_equal RECORDS[i][:state], r.state
|
85
|
+
assert_equal RECORDS[i][:statedate], r.statedate
|
86
|
+
assert_equal DEMOGRAPHICS[i], r.demographics
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_query_all_empty
|
91
|
+
records = Mosaic::Lyris::Record.query(:all, :list_id => 2)
|
92
|
+
assert_instance_of Array, records
|
93
|
+
assert_equal 0, records.size
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_query_all_paginated
|
97
|
+
i = 0
|
98
|
+
(1..3).each do |page|
|
99
|
+
records = Mosaic::Lyris::Record.query(:all, :list_id => 3, :page => page, :per_page => 4)
|
100
|
+
assert_instance_of Array, records
|
101
|
+
if page < 3
|
102
|
+
assert_equal 4, records.size
|
103
|
+
else
|
104
|
+
assert_equal 2, records.size
|
105
|
+
end
|
106
|
+
records.each do |r|
|
107
|
+
assert_instance_of Mosaic::Lyris::Record, r
|
108
|
+
assert_equal 'abcdef%04d' % (i+1), r.id
|
109
|
+
assert_equal RECORDS[i][:email], r.email
|
110
|
+
assert_equal RECORDS[i][:proof], r.proof
|
111
|
+
assert_equal RECORDS[i][:trashed], r.trashed
|
112
|
+
assert_equal RECORDS[i][:state], r.state
|
113
|
+
assert_equal RECORDS[i][:statedate], r.statedate
|
114
|
+
assert_equal DEMOGRAPHICS[i], r.demographics
|
115
|
+
i += 1
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
def test_query_active_email
|
121
|
+
record = Mosaic::Lyris::Record.query('active@email.not', :list_id => 1)
|
122
|
+
assert_instance_of Mosaic::Lyris::Record, record
|
123
|
+
assert_equal 'abcdef1111', record.id
|
124
|
+
assert_equal 'active@email.not', record.email
|
125
|
+
assert_equal true, record.proof
|
126
|
+
assert_equal false, record.trashed
|
127
|
+
assert_equal 'active', record.state
|
128
|
+
assert_equal Time.parse("2001-01-11 01:01:01 PST"), record.joindate
|
129
|
+
assert_equal nil, record.statedate
|
130
|
+
assert_equal({ 2 => '01/11/81', 7 => 'this email is active' }, record.demographics)
|
131
|
+
end
|
132
|
+
|
133
|
+
def test_query_admin_trashed_email
|
134
|
+
record = Mosaic::Lyris::Record.query('admin.trashed@email.not', :list_id => 1)
|
135
|
+
assert_instance_of Mosaic::Lyris::Record, record
|
136
|
+
assert_equal 'abcdef2222', record.id
|
137
|
+
assert_equal 'admin.trashed@email.not', record.email
|
138
|
+
assert_equal nil, record.proof
|
139
|
+
assert_equal true, record.trashed
|
140
|
+
assert_equal 'admin', record.state
|
141
|
+
assert_equal Time.parse("2002-02-12 02:02:02 PST"), record.joindate
|
142
|
+
assert_equal Date.new(2009,11,17), record.statedate
|
143
|
+
assert_equal({ 2 => '02/12/82', 7 => 'this email is admin trashed' }, record.demographics)
|
144
|
+
end
|
145
|
+
|
146
|
+
def test_query_bounced_email
|
147
|
+
record = Mosaic::Lyris::Record.query('bounced@email.not', :list_id => 1)
|
148
|
+
assert_instance_of Mosaic::Lyris::Record, record
|
149
|
+
assert_equal 'abcdef3333', record.id
|
150
|
+
assert_equal 'bounced@email.not', record.email
|
151
|
+
assert_equal nil, record.proof
|
152
|
+
assert_equal true, record.trashed
|
153
|
+
assert_equal 'bounced', record.state
|
154
|
+
assert_equal Time.parse("2003-03-13 03:03:03 PST"), record.joindate
|
155
|
+
assert_equal Date.new(2009,11,17), record.statedate
|
156
|
+
assert_equal({ 2 => '03/13/93', 7 => 'this email is bounced' }, record.demographics)
|
157
|
+
end
|
158
|
+
|
159
|
+
def test_query_unsubscribed_email
|
160
|
+
record = Mosaic::Lyris::Record.query('unsubscribed@email.not', :list_id => 1)
|
161
|
+
assert_instance_of Mosaic::Lyris::Record, record
|
162
|
+
assert_equal 'abcdef4444', record.id
|
163
|
+
assert_equal 'unsubscribed@email.not', record.email
|
164
|
+
assert_equal nil, record.proof
|
165
|
+
assert_equal true, record.trashed
|
166
|
+
assert_equal 'unsubscribed', record.state
|
167
|
+
assert_equal Time.parse("2004-04-14 04:04:04 PDT"), record.joindate
|
168
|
+
assert_equal Date.new(2009,11,17), record.statedate
|
169
|
+
assert_equal({ 2 => '04/14/94', 7 => 'this email is unsubscribed' }, record.demographics)
|
170
|
+
end
|
171
|
+
|
172
|
+
def test_query_email_not_found
|
173
|
+
assert_raise Mosaic::Lyris::Error do
|
174
|
+
record = Mosaic::Lyris::Record.query('missing@email.not', :list_id => 1)
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|