Skip to content

Commit

Permalink
Controllers uses CreatesInterestedPartiesCSV class for CSV
Browse files Browse the repository at this point in the history
  • Loading branch information
coreyhaines committed Oct 28, 2011
1 parent a8f9652 commit e60faa5
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 3 deletions.
10 changes: 7 additions & 3 deletions app/controllers/status_controller.rb
@@ -1,10 +1,14 @@
class StatusController < ApplicationController
def index
@total_addresses_collected = InterestedParty.total_collected


respond_to do |format|
format.html
format.csv { send_data "email_address", type: "text/csv", filename: "foo.csv", }
format.html do
@total_addresses_collected = InterestedParty.total_collected
end
format.csv do
send_data LaunchApp::CreatesInterestedPartiesCSV.for_all, type: "text/csv", filename: "foo.csv"
end
end
end
end
5 changes: 5 additions & 0 deletions app/launch_app/creates_interested_parties_csv.rb
@@ -0,0 +1,5 @@
module LaunchApp
class CreatesInterestedPartiesCSV
end
end

Expand Up @@ -8,3 +8,9 @@ Feature: Downloading details about interested parties
When I download the interested party details as csv
Then I should have an empty csv


Scenario: Somebody is interested
Given somebody has given me their email address
When I download the interested party details as csv
Then I should see the interested parties csv

7 changes: 7 additions & 0 deletions features/step_definitions/status_page_steps.rb
Expand Up @@ -26,3 +26,10 @@
actual_lines.should == ["email_address"]
end

Then /^I should see the interested parties csv$/ do
page.response_headers['Content-Type'].should == "text/csv"
actual_lines = page.text.split("\n")
actual_lines.length.should == 2
actual_lines.should == ["email_address", InterestedParty.last.email_address]
end

9 changes: 9 additions & 0 deletions spec/controllers/status_controller_spec.rb
Expand Up @@ -10,11 +10,20 @@
end

context "as a csv file" do
before do
LaunchApp::CreatesInterestedPartiesCSV.stub(:for_all)
end
it "supports it" do
get :index, format: :csv
response.should be_success
response.content_type.should == 'text/csv'
end

it "includes the email addresses collected" do
LaunchApp::CreatesInterestedPartiesCSV.stub(:for_all) { "this is the csv" }
get :index, format: :csv
response.body.should == "this is the csv"
end
end
end
end

0 comments on commit e60faa5

Please sign in to comment.