Browse files

Controllers uses CreatesInterestedPartiesCSV class for CSV

  • Loading branch information...
1 parent a8f9652 commit e60faa58a37c964544a08a826400d9d7dbc16999 @coreyhaines committed Oct 28, 2011
View
10 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
View
5 app/launch_app/creates_interested_parties_csv.rb
@@ -0,0 +1,5 @@
+module LaunchApp
+ class CreatesInterestedPartiesCSV
+ end
+end
+
View
6 features/status_results/downloading_interested_party_details.feature
@@ -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
+
View
7 features/step_definitions/status_page_steps.rb
@@ -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
+
View
9 spec/controllers/status_controller_spec.rb
@@ -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.