From fbeafd4299619f073d8092fb2371ea67236b9f6e Mon Sep 17 00:00:00 2001 From: Skud Date: Sat, 30 Aug 2014 11:28:52 +1000 Subject: [PATCH] Improving test coverage for gardens --- app/controllers/gardens_controller.rb | 2 +- spec/features/gardens.rb | 40 ++++++++++++++++++++++++++- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/app/controllers/gardens_controller.rb b/app/controllers/gardens_controller.rb index e77c22a1b..570dcdfca 100644 --- a/app/controllers/gardens_controller.rb +++ b/app/controllers/gardens_controller.rb @@ -85,7 +85,7 @@ class GardensController < ApplicationController @garden.destroy respond_to do |format| - format.html { redirect_to @garden.owner, notice: 'Garden was successfully deleted.' } + format.html { redirect_to gardens_by_owner_path(:owner => @garden.owner), notice: 'Garden was successfully deleted.' } format.json { head :no_content } end end diff --git a/spec/features/gardens.rb b/spec/features/gardens.rb index fff4d214b..1b803a41e 100644 --- a/spec/features/gardens.rb +++ b/spec/features/gardens.rb @@ -5,10 +5,19 @@ feature "Planting a crop", :js => true do background do login_as(garden.owner) - visit garden_path(garden) + end + + scenario "View gardens" do + visit gardens_path + expect(page).to have_content "Everyone's gardens" + click_link "View your gardens" + expect(page).to have_content "#{garden.owner.login_name}'s gardens" + click_link "View everyone's gardens" + expect(page).to have_content "Everyone's gardens" end scenario "Marking a garden as inactive" do + visit garden_path(garden) click_link "Mark as inactive" expect(page).to have_content "Garden was successfully updated" expect(page).to have_content "This garden is inactive" @@ -16,4 +25,33 @@ feature "Planting a crop", :js => true do expect(page).not_to have_content "Mark as inactive" end + scenario "Create new garden" do + visit new_garden_path + fill_in "Name", :with => "New garden" + click_button "Save" + expect(page).to have_content "Garden was successfully created" + expect(page).to have_content "New garden" + end + + scenario "Edit garden" do + visit new_garden_path + fill_in "Name", :with => "New garden" + click_button "Save" + click_link "Edit garden" + fill_in "Name", :with => "Different name" + click_button "Save" + expect(page).to have_content "Garden was successfully updated" + expect(page).to have_content "Different name" + end + + scenario "Delete garden" do + visit new_garden_path + fill_in "Name", :with => "New garden" + click_button "Save" + visit garden_path(Garden.last) + click_link "Delete garden" + expect(page).to have_content "Garden was successfully deleted" + expect(page).to have_content "#{garden.owner}'s gardens" + end + end