Permalink
Browse files

CSV download of emails.

  • Loading branch information...
1 parent 08bc7b1 commit 04e21120e762e796d86fbde49d977285fde21c4a @markoa markoa committed Dec 13, 2010
Showing with 40 additions and 1 deletion.
  1. +1 −0 Gemfile
  2. +2 −0 Gemfile.lock
  3. +13 −0 coming_soon.rb
  4. +10 −0 features/cablegate.feature
  5. +13 −0 features/step_definitions/user_steps.rb
  6. +1 −1 views/backstage.erb
View
@@ -2,6 +2,7 @@ source 'http://rubygems.org'
gem 'sinatra'
gem 'activerecord', '3.0.0'
+gem 'fastercsv'
group :test do
gem 'database_cleaner'
View
@@ -25,6 +25,7 @@ GEM
database_cleaner (0.5.2)
diff-lcs (1.1.2)
extlib (0.9.15)
+ fastercsv (1.5.3)
gherkin (2.1.5)
trollop (~> 1.16.2)
highline (1.5.0)
@@ -49,4 +50,5 @@ DEPENDENCIES
cucumber
cucumber-sinatra
database_cleaner
+ fastercsv
sinatra
View
@@ -1,5 +1,6 @@
require 'sinatra/base'
require 'active_record'
+require 'fastercsv'
def load_configuration(file, name)
@@ -61,6 +62,18 @@ class User < ActiveRecord::Base
erb :backstage
end
+ get '/backstage/csv' do
+ csv_content = FasterCSV.generate do |csv|
+ User.find_each do |user|
+ csv << [user.email]
+ end
+ end
+
+ headers "Content-Disposition" => "attachment;filename=emails.csv",
+ "Content-Type" => "text/csv"
+ csv_content
+ end
+
##
helpers do
View
@@ -8,3 +8,13 @@ I should be able to see how many signed up and export emails in a CSV file
When I go to the admin page
Then I should see "1 person signed up"
And I should see "Download emails in a CSV file"
+
+ Scenario: Downloading emails in CSV file
+ Given there are no emails
+ And "dieter@gmail.com" signed up
+ And "karin@gmail.com" signed up
+ When I go to the admin page
+ And I follow "Download emails in a CSV file"
+ Then I should receive CSV file
+ And CSV file should contain "dieter@gmail.com"
+ And CSV file should contain "karin@gmail.com"
@@ -7,3 +7,16 @@
ComingSoon::User.create(:email => "julian.lieberman@gmail.com",
:referer => "http://twitter.com")
end
+
+Given /^"([^"]*)" signed up$/ do |email|
+ ComingSoon::User.create(:email => email)
+end
+
+Then /^I should receive CSV file$/ do
+ page.response_headers["Content-Type"].should == "text/csv"
+end
+
+Then /^CSV file should contain "([^"]*)"$/ do |email|
+ emails = FasterCSV.parse(page.body)
+ emails.should include [email]
+end
View
@@ -2,4 +2,4 @@
<h2><%= pluralize(@user_count, "person", "people") %> signed up.</h2>
-<a href="/">Download emails in a CSV file</a>
+<a href="/backstage/csv">Download emails in a CSV file</a>

0 comments on commit 04e2112

Please sign in to comment.