|
76 | 76 | expect(donation_site.errors.full_messages).to eq(["Cannot delete record because dependent donations exist"]) |
77 | 77 | end |
78 | 78 | end |
| 79 | + |
| 80 | + describe "CSV headers" do |
| 81 | + it "returns the correct headers for the CSV export" do |
| 82 | + expected_headers = ["Name", "Address", "Contact Name", "Email", "Phone"] |
| 83 | + expect(DonationSite.csv_export_headers).to eq(expected_headers) |
| 84 | + end |
| 85 | + end |
| 86 | + |
| 87 | + describe "CSV export attributes" do |
| 88 | + let(:organization) { create(:organization) } |
| 89 | + let!(:active_donation_site) { create(:donation_site, name: "Active Site", address: "1500 Remount Road, Front Royal, VA 22630", active: true, organization: organization) } |
| 90 | + let!(:inactive_donation_site) { create(:donation_site, name: "Inactive Site", address: "1500 Remount Road, Front Royal, VA 22630", active: false, organization: organization) } |
| 91 | + |
| 92 | + context "when there are active and inactive donation sites" do |
| 93 | + it "includes only active donation sites in the CSV export" do |
| 94 | + csv_data = DonationSite.active.map(&:csv_export_attributes) |
| 95 | + |
| 96 | + expect(csv_data.count).to eq(1) |
| 97 | + |
| 98 | + expect(csv_data.first).to eq([ |
| 99 | + active_donation_site.name, |
| 100 | + active_donation_site.address, |
| 101 | + active_donation_site.contact_name, |
| 102 | + active_donation_site.email, |
| 103 | + active_donation_site.phone |
| 104 | + ]) |
| 105 | + end |
| 106 | + end |
| 107 | + |
| 108 | + context "when all donation sites are inactive" do |
| 109 | + it "returns no donation sites in the CSV export" do |
| 110 | + csv_data = DonationSite.active.map(&:csv_export_attributes) |
| 111 | + expect(csv_data).to be_empty |
| 112 | + end |
| 113 | + # Deactivate both :active_donation_site and :inactive_donation_site |
| 114 | + before do |
| 115 | + active_donation_site.update(active: false) |
| 116 | + end |
| 117 | + end |
| 118 | + |
| 119 | + context "when both donation sites are active" do |
| 120 | + it "includes both active donation sites in the CSV export" do |
| 121 | + csv_data = DonationSite.active.map(&:csv_export_attributes) |
| 122 | + |
| 123 | + expect(csv_data.count).to eq(2) |
| 124 | + |
| 125 | + expect(csv_data.first).to eq([ |
| 126 | + active_donation_site.name, |
| 127 | + active_donation_site.address, |
| 128 | + active_donation_site.contact_name, |
| 129 | + active_donation_site.email, |
| 130 | + active_donation_site.phone |
| 131 | + ]) |
| 132 | + |
| 133 | + expect(csv_data.second).to eq([ |
| 134 | + inactive_donation_site.name, |
| 135 | + inactive_donation_site.address, |
| 136 | + inactive_donation_site.contact_name, |
| 137 | + inactive_donation_site.email, |
| 138 | + inactive_donation_site.phone |
| 139 | + ]) |
| 140 | + end |
| 141 | + # Activate both :active_donation_site and :inactive_donation_site |
| 142 | + before do |
| 143 | + active_donation_site.update(active: true) |
| 144 | + inactive_donation_site.update(active: true) |
| 145 | + end |
| 146 | + end |
| 147 | + end |
79 | 148 | end |
0 commit comments