Commit ea767f367cd97133c08aff764cca8b0dbce9e7b5
1 parent
c57d22d8
Exists in
master
and in
29 other branches
Adds functional test for exporting as csv
Showing
1 changed file
with
20 additions
and
0 deletions
Show diff stats
plugins/custom_forms/test/functional/custom_forms_plugin_myprofile_controller_test.rb
... | ... | @@ -180,6 +180,26 @@ class CustomFormsPluginMyprofileControllerTest < ActionController::TestCase |
180 | 180 | assert_equal 'Source', field.name |
181 | 181 | end |
182 | 182 | |
183 | + should 'export submissions as csv' do | |
184 | + form = CustomFormsPlugin::Form.create!(:profile => profile, :name => 'Free Software') | |
185 | + field = CustomFormsPlugin::TextField.create!(:name => "Title") | |
186 | + form.fields << field | |
187 | + | |
188 | + answer = CustomFormsPlugin::Answer.create!(:value => 'example', :field => field) | |
189 | + | |
190 | + sub1 = CustomFormsPlugin::Submission.create!(:author_name => "john", :author_email => 'john@example.com', :form => form) | |
191 | + sub1.answers << answer | |
192 | + | |
193 | + bob = create_user('bob').person | |
194 | + sub2 = CustomFormsPlugin::Submission.create!(:profile => bob, :form => form) | |
195 | + | |
196 | + get :submissions, :profile => profile.identifier, :id => form.id, :format => 'csv' | |
197 | + assert_equal @response.content_type, 'text/csv' | |
198 | + assert_equal @response.body.split("\n")[0], 'Timestamp,Name,Email,Title' | |
199 | + assert_equal @response.body.split("\n")[1], "#{sub1.updated_at.strftime('%Y/%m/%d %T %Z')},john,john@example.com,example" | |
200 | + assert_equal @response.body.split("\n")[2], "#{sub2.updated_at.strftime('%Y/%m/%d %T %Z')},bob,#{bob.email},\"\"" | |
201 | + end | |
202 | + | |
183 | 203 | should 'order submissions by name or time' do |
184 | 204 | form = CustomFormsPlugin::Form.create!(:profile => profile, :name => 'Free Software') |
185 | 205 | field = CustomFormsPlugin::TextField.create!(:name => "Title") | ... | ... |