|
218 | 218 | # Bug fix -- Issue #378 |
219 | 219 | # A user can view another organizations purchase |
220 | 220 | context "Editing purchase" do |
221 | | - it "A user can see purchased_from value" do |
222 | | - purchase = create(:purchase, purchased_from: "Old Vendor", organization: organization) |
223 | | - visit edit_purchase_path(purchase) |
224 | | - expect(page).to have_content("Vendor (Old Vendor)") |
| 221 | + context "with an eligible purchase" do |
| 222 | + let(:purchase) { create(:purchase, purchased_from: "Old Vendor", organization: organization) } |
| 223 | + |
| 224 | + it "can view the edit page and vendor is present" do |
| 225 | + visit edit_purchase_path(purchase) |
| 226 | + |
| 227 | + expect(page).to have_content("Vendor (Old Vendor)") |
| 228 | + end |
| 229 | + |
| 230 | + it "can save the purchase" do |
| 231 | + visit edit_purchase_path(purchase) |
| 232 | + click_button "Save" |
| 233 | + |
| 234 | + expect(page).to have_content("Purchase updated successfully") |
| 235 | + expect(page.current_path).to eq(purchases_path) |
| 236 | + end |
| 237 | + |
| 238 | + context "with an error saving the purchase" do |
| 239 | + it "can save the purchase from the update page " do |
| 240 | + visit edit_purchase_path(purchase) |
| 241 | + |
| 242 | + fill_in "purchase[amount_spent]", with: nil |
| 243 | + |
| 244 | + click_button "Save" |
| 245 | + |
| 246 | + expect(page).to have_content("Error updating purchase") |
| 247 | + expect(page.current_path).to eq(purchase_path(purchase)) |
| 248 | + |
| 249 | + fill_in "purchase[amount_spent]", with: "10" |
| 250 | + |
| 251 | + click_button "Save" |
| 252 | + |
| 253 | + expect(page).to have_content("Purchase updated successfully") |
| 254 | + expect(page.current_path).to eq(purchases_path) |
| 255 | + end |
| 256 | + end |
| 257 | + |
| 258 | + context "with a deactivated vendor" do |
| 259 | + let(:deactivated_vendor) { create(:vendor, active: false) } |
| 260 | + let(:purchase) { create(:purchase, vendor: deactivated_vendor) } |
| 261 | + |
| 262 | + it "can save the purchase" do |
| 263 | + visit edit_purchase_path(purchase) |
| 264 | + click_button "Save" |
| 265 | + |
| 266 | + expect(page).to have_content("Purchase updated successfully") |
| 267 | + expect(page.current_path).to eq(purchases_path) |
| 268 | + end |
| 269 | + end |
225 | 270 | end |
226 | 271 |
|
227 | | - it "A user can view another organizations purchase" do |
228 | | - purchase = create(:purchase, organization: create(:organization)) |
229 | | - visit edit_purchase_path(purchase) |
230 | | - expect(page).to have_content("Still haven't found what you're looking for") |
| 272 | + context "with another organization's purchase" do |
| 273 | + let(:another_organization) { create(:organization) } |
| 274 | + let(:purchase) { create(:purchase, organization: another_organization) } |
| 275 | + |
| 276 | + it "cannot view the edit page" do |
| 277 | + visit edit_purchase_path(purchase) |
| 278 | + |
| 279 | + expect(page).to have_content("Still haven't found what you're looking for") |
| 280 | + end |
231 | 281 | end |
232 | 282 | end |
233 | 283 |
|
|
0 commit comments