|
e5822a26
»
|
jnunemaker |
2008-12-16 |
Refactored to now use clien... |
1 |
require File.dirname(__FILE__) + '/test_helper' |
| |
2 |
|
| |
3 |
class TestSubmission < Test::Unit::TestCase |
| |
4 |
before do |
| |
5 |
@client = Wufoo::Client.new('http://foobar.wufoo.com', 'somecrazyapikey') |
| |
6 |
end |
| |
7 |
|
| |
8 |
test 'initialize' do |
| |
9 |
submission = Wufoo::Submission.new(@client, 'my-crazy-form') |
| |
10 |
assert_equal(@client, submission.client) |
| |
11 |
assert_equal('my-crazy-form', submission.form) |
| |
12 |
assert_equal({}, submission.params) |
| |
13 |
end |
| |
14 |
|
| |
15 |
test 'initialize with params' do |
| |
16 |
submission = Wufoo::Submission.new(@client, 'my-crazy-form', {'0' => 'Foo'}) |
| |
17 |
assert_equal({'0' => 'Foo'}, submission.params) |
| |
18 |
end |
| |
19 |
|
| |
20 |
test 'add_params' do |
| |
21 |
submission = Wufoo::Submission.new(@client, 'my-crazy-form').add_params('0' => 'Foo') |
| |
22 |
assert_equal({'0' => 'Foo'}, submission.params) |
| |
23 |
end |
| |
24 |
|
| |
25 |
test 'add_params returns self' do |
| |
26 |
assert_kind_of(Wufoo::Submission, Wufoo::Submission.new(@client, 'my-crazy-form').add_params('0' => 'Foo')) |
| |
27 |
end |
| |
28 |
|
| |
29 |
context 'processing response that was successful' do |
| |
30 |
before do |
| |
31 |
@client.stub!(:post, :return => successful_response_data) |
| |
32 |
submission = Wufoo::Submission.new(@client, 'my-crazy-form').add_params({'0' => 'Foobar!'}) |
| |
33 |
@response = submission.process |
| |
34 |
end |
| |
35 |
|
| |
36 |
test 'should have data' do |
| |
37 |
assert_equal(successful_response_data, @response.data) |
| |
38 |
end |
| |
39 |
|
| |
40 |
test 'should be success?' do |
| |
41 |
assert @response.success? |
| |
42 |
end |
| |
43 |
|
| |
44 |
test 'should not be fail?' do |
| |
45 |
assert ! @response.fail? |
| |
46 |
end |
| |
47 |
|
| |
48 |
test 'should be valid?' do |
| |
49 |
assert @response.valid? |
| |
50 |
end |
| |
51 |
|
| |
52 |
test 'should have message' do |
| |
53 |
assert_equal('Success! Thanks for filling out my form!', @response.message) |
| |
54 |
end |
| |
55 |
|
| |
56 |
test 'should have entry_id' do |
| |
57 |
assert_equal('1025', @response.entry_id) |
| |
58 |
end |
| |
59 |
|
| |
60 |
test 'should not have error' do |
| |
61 |
assert_equal('', @response.error) |
| |
62 |
end |
| |
63 |
|
| |
64 |
test 'should not have errors' do |
| |
65 |
assert_equal([], @response.errors) |
| |
66 |
end |
| |
67 |
end |
| |
68 |
|
| |
69 |
context 'processing a response that failed' do |
| |
70 |
before do |
| |
71 |
@client.stub!(:post, :return => error_response_data) |
| |
72 |
submission = Wufoo::Submission.new(@client, 'my-crazy-form').add_params({'0' => 'Foobar!'}) |
| |
73 |
@response = submission.process |
| |
74 |
end |
| |
75 |
|
| |
76 |
test 'should have data' do |
| |
77 |
assert_equal(error_response_data, @response.data) |
| |
78 |
end |
| |
79 |
|
| |
80 |
test 'should not be success?' do |
| |
81 |
assert ! @response.success? |
| |
82 |
end |
| |
83 |
|
| |
84 |
test 'should be a fail?' do |
| |
85 |
assert @response.fail? |
| |
86 |
end |
| |
87 |
|
| |
88 |
test 'should be valid?' do |
| |
89 |
assert @response.valid? |
| |
90 |
end |
| |
91 |
|
| |
92 |
test 'should have error' do |
| |
93 |
assert_equal('The supplied form URL was not found.', @response.error) |
| |
94 |
end |
| |
95 |
end |
| |
96 |
|
| |
97 |
context 'processing a response with field errors' do |
| |
98 |
before do |
| |
99 |
@client.stub!(:post, :return => field_error_response_data) |
| |
100 |
submission = Wufoo::Submission.new(@client, 'my-crazy-form').add_params({'0' => 'Foobar!'}) |
| |
101 |
@response = submission.process |
| |
102 |
end |
| |
103 |
|
| |
104 |
test 'should have data' do |
| |
105 |
assert_equal(field_error_response_data, @response.data) |
| |
106 |
end |
| |
107 |
|
| |
108 |
test 'should not be success?' do |
| |
109 |
assert ! @response.success? |
| |
110 |
end |
| |
111 |
|
| |
112 |
test 'should not be fail?' do |
| |
113 |
assert ! @response.fail? |
| |
114 |
end |
| |
115 |
|
| |
116 |
test 'should not be valid?' do |
| |
117 |
assert ! @response.valid? |
| |
118 |
end |
| |
119 |
|
| |
120 |
test 'should have errors' do |
| |
121 |
field_ids = ['field0', 'field1'] |
| |
122 |
messages = ['Invalid email address.', 'Field is required.'] |
| |
123 |
codes = ['2', '0'] |
| |
124 |
assert_equal(field_ids, @response.errors.collect { |e| e.field_id }) |
| |
125 |
assert_equal(messages, @response.errors.collect { |e| e.message }) |
| |
126 |
assert_equal(codes, @response.errors.collect { |e| e.code }) |
| |
127 |
end |
| |
128 |
end |
| |
129 |
end |